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

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

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

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

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