From 319dd896f3a44237e1c26f3887fcb259f80f2714 Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Thu, 11 Nov 2021 23:10:03 +0100 Subject: clean code and add notifications --- src/services/AuthService.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src/services/AuthService.js') diff --git a/src/services/AuthService.js b/src/services/AuthService.js index 626a8fb..402d196 100644 --- a/src/services/AuthService.js +++ b/src/services/AuthService.js @@ -1,17 +1,47 @@ import axios from "axios"; +import Vue from 'vue' const url = 'http://localhost:8000/api/auth/' +const error_notify = (error) => { + for (const [key, values] of Object.entries(error.response.data)) { + values.forEach(value => { + Vue.notify({ + type: 'error', + title: value, + text: key + }) + }) + } + return { + data: error.response.data, + status: error.response.status + } +} + export default { async login(data) { return await axios .post(url+'login/', data) - .then(res => res.data) + .then(res => { + return { + data: res.data, + status: res.status + } + }) + .catch(error => error_notify(error)) }, async register(data) { return await axios .post(url+'register/', data) - .then(res => res.data) + .then(res => { + return { + data: res.data, + status: res.status + } + }) + .catch(error => error_notify(error)) + } } \ No newline at end of file -- cgit v1.2.3