자동 로그인, 로그아웃 추적2
This commit is contained in:
parent
b021b7beea
commit
afe0a377db
@ -6,6 +6,11 @@ import { useAxios } from '@/hooks/useAxios'
|
||||
import { logout } from '@/lib/authActions'
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
/**
|
||||
* 로그아웃 처리 Hook
|
||||
* - 로그아웃 API 호출 후 성공/실패 상관없이 로그아웃 처리
|
||||
* - Header, ChangePasswordPop 등에서 공통으로 사용
|
||||
*/
|
||||
export function useLogout() {
|
||||
const [sessionState] = useRecoilState(sessionStore)
|
||||
const [stuffSearch, setStuffSearch] = useRecoilState(stuffSearchState)
|
||||
@ -15,22 +20,24 @@ export function useLogout() {
|
||||
const logoutProcess = async () => {
|
||||
const param = {
|
||||
loginId: sessionState.userId,
|
||||
requestId: Cookies.get('sessionId'),
|
||||
requestId: Cookies.get('sessionId'), // 로그인 시 저장한 sessionId
|
||||
}
|
||||
|
||||
// 로그아웃 API 호출 (실패해도 로그아웃 진행)
|
||||
try {
|
||||
await promisePost({ url: '/api/login/v1.0/logout', data: param })
|
||||
} catch (error) {
|
||||
console.log('logout api error:', error)
|
||||
}
|
||||
|
||||
// 물건검색 상태 초기화
|
||||
setStuffSearch({
|
||||
...stuffSearch,
|
||||
code: 'DELETE',
|
||||
})
|
||||
Cookies.remove('sessionId')
|
||||
await logout()
|
||||
window.location.href = '/login'
|
||||
Cookies.remove('sessionId') // sessionId 쿠키 삭제
|
||||
await logout() // iron-session 세션 파기
|
||||
window.location.href = '/login' // 로그인 페이지로 이동 (full reload)
|
||||
}
|
||||
|
||||
return { logoutProcess }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user