auth.js 499 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
8
9
10
}


export async function handleLogout() {
Choi Ga Young's avatar
aa    
Choi Ga Young committed
11
    sessionStorage.clear();
12
    await axios.get('/auth/logout')
13
14
15
}

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