auth.js 707 Bytes
Newer Older
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
1
2
import axios from "axios"

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
3
export function handleLogin(userId) { //로그인할때 로컬스토리지에 유저 아이디를 설정한다
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
4
5
6
7
    localStorage.setItem('loginStatus', userId)
}

export async function handleLogout() {
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
8
9
    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
    }
}