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

//자동으로 localstorage에 login이 생성됨
우지원's avatar
우지원 committed
4
5
export function handleLogin(userId) {
    localStorage.setItem('user', userId)
우지원's avatar
01_06    
우지원 committed
6
}
우지원's avatar
우지원 committed
7

우지원's avatar
01_06    
우지원 committed
8
export async function handleLogout() {
9
10
    localStorage.removeItem('user')
    await axios.get('/auth/logout')
우지원's avatar
우지원 committed
11
12
13
14
15
16
    //login페이지로 이동
    window.location.href='/login'
}

//login이 됬는지 안됬는지 따질때 쓰임
export function isAuthenticated() {
우지원's avatar
0113    
우지원 committed
17
18
19
    const userId = localStorage.getItem('user')
    if (userId) {
        return userId
우지원's avatar
우지원 committed
20
21
22
    } else {
        return false
    }
우지원's avatar
01_06    
우지원 committed
23
}