diff options
Diffstat (limited to 'src/services')
-rw-r--r-- | src/services/AuthService.js | 34 |
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 @@ | |||
1 | import axios from "axios"; | 1 | import axios from "axios"; |
2 | import Vue from 'vue' | ||
2 | 3 | ||
3 | const url = 'http://localhost:8000/api/auth/' | 4 | const url = 'http://localhost:8000/api/auth/' |
4 | 5 | ||
6 | const 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 | |||
5 | export default { | 22 | export 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 |