summaryrefslogtreecommitdiffstats
path: root/src/services/AuthService.js
blob: 402d196365d8bc323f787718ee547f099a5e19ed (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
            })
        })
    }
    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))

    }
}