auth.js 746 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() {
baesangjune's avatar
baesangjune committed
8
    alert("로그아웃되었습니다.")
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
9
    localStorage.removeItem('loginStatus') //로컬스토리지에서 로그인상태를 지운다
Lee SeoYeon's avatar
..    
Lee SeoYeon committed
10
    await axios.get('/api/auth/logout') 
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
11
    window.location.href='/' //경로 지정
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
12
}
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
13
//유저가 로그인 했는 지 확인하는 함수
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
14
export function isAuthenticated() {
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
15
    const userId = localStorage.getItem('loginStatus') //유저아이디를 로컬스토리지에서 가져와서 저장
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
16
17
18
19
20
21
    if (userId) {
        return userId
    }else{
        return false
    }
}