auth.js 758 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
6
    localStorage.setItem('id', userId)
    localStorage.setItem('role', role)
    localStorage.setItem('name', name)
kusang96's avatar
dd    
kusang96 committed
7
    localStorage.setItem('tel', tel)
Jiwon Yoon's avatar
Jiwon Yoon committed
8
    localStorage.setItem('email', email)
이재연's avatar
이재연 committed
9
10
}

kusang96's avatar
kusang96 committed
11
export async function handleLogout() {
kusang96's avatar
dd    
kusang96 committed
12
    localStorage.clear()
이재연'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
}