blob: ff1e468a7350221cc06ff8e98a7e84457ded4cf8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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 !== 'non_field_errors') ? key : ''
})
})
}
return {
data: error.response.data,
status: error.response.status
}
}
export default {
async login(data) {
return await axios
.post(url+'login/', 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 => {
return {
data: res.data,
status: res.status
}
})
.catch(error => error_notify(error))
}
}
|