Auth.js 1.48 KB
Newer Older
1
import axios from 'axios';
2
import { checkCookies } from './CheckDB';
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

export function handleLogin({ userId, role, name, tel, email }) {
    localStorage.setItem('id', userId)
    localStorage.setItem('role', role)
    localStorage.setItem('name', name)
    localStorage.setItem('tel', tel)
    localStorage.setItem('email', email)
}

export async function handleLogout() {
    localStorage.clear()
    await axios.get('/api/auth/logout')
    window.location.href = '/'
}

export function isLogined() {
19
    const userId = checkCookies()
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    if (userId) {
        return userId
    } else {
        return false
    }
}

export function isAdmin() {
    const role = localStorage.getItem('role')
    if (role === 'admin') {
        return true
    } else {
        return false
    }
}
Spark's avatar
Spark committed
35
36
37
38
39


export function isOauth(value) {
    const TFoauth = value
    return TFoauth;
Spark's avatar
Spark committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
}

// export async function doeCode() {
//     const response = await axios.get('http://175.125.254.72:8090/api/data/loccode')

//     // console.log('res::', response.data.locCodes)

//     const resData = response.data.locCodes
//     const doe = resData.DOE
//     // console.log('dd', doe) //object
//     // console.log('dd::', doe[doe.length-1])
//     // console.log('values::', Object.values(doe))
//     const doeValue = Object.values(doe)
//     // console.log('@@@11', doeValue[0]['code_doe'], typeof(doeValue[0]['code_doe']))
//     // console.log('@@@22', doeValue[0]['name_doe'], typeof(doeValue[0]['name_doe']))

//     return doeValue
// }