Auth.js 898 Bytes
Newer Older
1
import axios from 'axios';
Spark's avatar
Spark committed
2
3
import { useState } from 'react';
import Oauth from './Oauth';
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

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() {
    const userId = localStorage.getItem('id')
    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
36
37
38
39
40
41


export function isOauth(value) {
    const TFoauth = value
    return TFoauth;
}