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

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

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

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

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