auth.js 574 Bytes
Newer Older
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
1
2
3
4
5
6
7
8
9
import axios from "axios"

export function handleLogin(userId) {
    localStorage.setItem('loginStatus', userId)
}

export async function handleLogout() {
    localStorage.removeItem('loginStatus')
    await axios.get('/api/auth/logout')
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
10
    window.location.href='/' //경로 지정
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
11
}
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
12
//유저가 로그인 했는 지 확인하는 함수
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
13
export function isAuthenticated() {
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
14
    const userId = localStorage.getItem('loginStatus') //유저아이디를 로컬스토리지에서 가져와서 저장
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
15
16
17
18
19
20
    if (userId) {
        return userId
    }else{
        return false
    }
}