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