auth.js 540 Bytes
Newer Older
우지원's avatar
01_06    
우지원 committed
1
2
3
import axios from "axios"

//자동으로 localstorage에 login이 생성됨
4
export function handleLogin(data) {
Choi Ga Young's avatar
aa    
Choi Ga Young committed
5
6
    sessionStorage.setItem('userId', data.user._id)
    sessionStorage.setItem('name', data.user.username)
우지원's avatar
01_06    
우지원 committed
7
}
우지원's avatar
우지원 committed
8

우지원's avatar
01_06    
우지원 committed
9
export async function handleLogout() {
Choi Ga Young's avatar
Choi Ga Young committed
10
    alert('로그아웃 되었습니다')
Choi Ga Young's avatar
aa    
Choi Ga Young committed
11
    sessionStorage.clear();
12
    await axios.get('/auth/logout')
우지원's avatar
우지원 committed
13
14
15
}

export function isAuthenticated() {
Choi Ga Young's avatar
aa    
Choi Ga Young committed
16
    const userId = sessionStorage.getItem('userId')
우지원's avatar
0113    
우지원 committed
17
18
    if (userId) {
        return userId
우지원's avatar
우지원 committed
19
20
21
    } else {
        return false
    }
우지원's avatar
01_06    
우지원 committed
22
}