auth.js 493 Bytes
Newer Older
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
1
2
3
import axios from 'axios'

export function handleLogin(userId) {
이재연's avatar
이재연 committed
4
  sessionStorage.setItem("user", userId)
Kim, Chaerin's avatar
시연2    
Kim, Chaerin committed
5
  localStorage.setItem("user", userId)
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
6
7
8
9
}

export async function handleLogout() {
  alert("로그아웃되었습니다.")
이재연's avatar
이재연 committed
10
  sessionStorage.removeItem("user")
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
11
12
13
14
15
  await axios.get('/api/auth/logout') 
  window.location.href='/'
}

export function isAuthenticated() {
이재연's avatar
이재연 committed
16
  const userId = sessionStorage.getItem('loginStatus')
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
17
18
19
20
21
22
  if (userId) {
      return userId
  }else{
      return false
  }
}