dev #755

Merged
ysCha merged 2 commits from dev into dev-deploy 2026-04-03 13:36:03 +09:00
Showing only changes of commit c6da437a8d - Show all commits

38
src/hooks/useLogout.js Normal file
View File

@ -0,0 +1,38 @@
import { useRecoilState, useRecoilValue } from 'recoil'
import { sessionStore } from '@/store/commonAtom'
import { globalLocaleStore } from '@/store/localeAtom'
import { stuffSearchState } from '@/store/stuffAtom'
import { useAxios } from '@/hooks/useAxios'
import { logout } from '@/lib/authActions'
import Cookies from 'js-cookie'
export function useLogout() {
const [sessionState] = useRecoilState(sessionStore)
const [stuffSearch, setStuffSearch] = useRecoilState(stuffSearchState)
const globalLocaleState = useRecoilValue(globalLocaleStore)
const { promisePost } = useAxios(globalLocaleState)
const logoutProcess = async () => {
const param = {
loginId: sessionState.userId,
requestId: Cookies.get('sessionId'),
}
await promisePost({ url: '/api/login/v1.0/logout', data: param })
.then(async (res) => {
if (res.data.result.resultCode === 'S') {
setStuffSearch({
...stuffSearch,
code: 'DELETE',
})
Cookies.remove('sessionId')
await logout()
window.location.href = '/login'
}
})
.catch((error) => {
alert(error.response?.data?.message || 'ログアウトに失敗しました。')
})
}
return { logoutProcess }
}