summaryrefslogtreecommitdiffstats
path: root/src/services
diff options
context:
space:
mode:
authorjdlugosz963 <jdlugosz963@gmail.com>2021-11-11 23:10:03 +0100
committerjdlugosz963 <jdlugosz963@gmail.com>2021-11-11 23:10:03 +0100
commit319dd896f3a44237e1c26f3887fcb259f80f2714 (patch)
tree7cca77696e363b614a8b1de20623c7bffccfbba0 /src/services
parent584275e57f57871ce1a3095be59c4ecb284a3c77 (diff)
downloadlom_frontend-319dd896f3a44237e1c26f3887fcb259f80f2714.tar.gz
lom_frontend-319dd896f3a44237e1c26f3887fcb259f80f2714.zip
clean code and add notifications
Diffstat (limited to 'src/services')
-rw-r--r--src/services/AuthService.js34
1 files changed, 32 insertions, 2 deletions
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 @@
1import axios from "axios"; 1import axios from "axios";
2import Vue from 'vue'
2 3
3const url = 'http://localhost:8000/api/auth/' 4const url = 'http://localhost:8000/api/auth/'
4 5
6const error_notify = (error) => {
7 for (const [key, values] of Object.entries(error.response.data)) {
8 values.forEach(value => {
9 Vue.notify({
10 type: 'error',
11 title: value,
12 text: key
13 })
14 })
15 }
16 return {
17 data: error.response.data,
18 status: error.response.status
19 }
20}
21
5export default { 22export default {
6 async login(data) { 23 async login(data) {
7 return await axios 24 return await axios
8 .post(url+'login/', data) 25 .post(url+'login/', data)
9 .then(res => res.data) 26 .then(res => {
27 return {
28 data: res.data,
29 status: res.status
30 }
31 })
32 .catch(error => error_notify(error))
10 }, 33 },
11 34
12 async register(data) { 35 async register(data) {
13 return await axios 36 return await axios
14 .post(url+'register/', data) 37 .post(url+'register/', data)
15 .then(res => res.data) 38 .then(res => {
39 return {
40 data: res.data,
41 status: res.status
42 }
43 })
44 .catch(error => error_notify(error))
45
16 } 46 }
17} \ No newline at end of file 47} \ No newline at end of file