auth.js 749 Bytes
Newer Older
kusang96's avatar
kusang96 committed
1
import axios from "axios";
이재연's avatar
이재연 committed
2

kusang96's avatar
kusang96 committed
3
4
5
6
export function handleLogin({ userId, role, name }) {
    localStorage.setItem('id', userId)
    localStorage.setItem('role', role)
    localStorage.setItem('name', name)
이재연's avatar
이재연 committed
7
8
}

kusang96's avatar
kusang96 committed
9
export async function handleLogout() {
이재연's avatar
0115    
이재연 committed
10
11
12
    localStorage.removeItem('id')
    localStorage.removeItem('role')
    localStorage.removeItem('name')
이재연's avatar
이재연 committed
13
    await axios.get('/api/auth/logout')
박상호's avatar
박상호 committed
14
    window.location.href = '/'
이재연's avatar
이재연 committed
15
16
}

kusang96's avatar
kusang96 committed
17
18
19
export function isAuthenticated() {
    const userId = localStorage.getItem('id')
    if (userId) {
이재연's avatar
이재연 committed
20
        return userId
박상호's avatar
박상호 committed
21
    } else {
kusang96's avatar
kusang96 committed
22
23
24
        return false
    }
}
박상호's avatar
박상호 committed
25

kusang96's avatar
kusang96 committed
26
27
28
29
30
31
export function isAdmin() {
    const role = localStorage.getItem('role')
    if (role === 'admin') {
        return true
    } else {
        return false
이재연's avatar
이재연 committed
32
    }
이재연's avatar
이재연 committed
33
}