Merge pull request 'dev' (#755) from dev into dev-deploy
Reviewed-on: #755
This commit is contained in:
commit
104f5a115c
@ -3,6 +3,7 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useMessage } from '@/hooks/useMessage'
|
import { useMessage } from '@/hooks/useMessage'
|
||||||
import { setSession, login } from '@/lib/authActions'
|
import { setSession, login } from '@/lib/authActions'
|
||||||
|
import Cookies from 'js-cookie'
|
||||||
import { sessionStore } from '@/store/commonAtom'
|
import { sessionStore } from '@/store/commonAtom'
|
||||||
import { useRecoilState } from 'recoil'
|
import { useRecoilState } from 'recoil'
|
||||||
import { useAxios } from '@/hooks/useAxios'
|
import { useAxios } from '@/hooks/useAxios'
|
||||||
@ -31,6 +32,7 @@ export default function AutoLoginPage({ autoLoginParam }) {
|
|||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
const res = response.data
|
const res = response.data
|
||||||
|
if (res.sessionId) Cookies.set('sessionId', res.sessionId)
|
||||||
const result = { ...res, storeLvl: res.groupId === '60000' ? '1' : '2', pwdInitYn: 'Y' }
|
const result = { ...res, storeLvl: res.groupId === '60000' ? '1' : '2', pwdInitYn: 'Y' }
|
||||||
setSession(result)
|
setSession(result)
|
||||||
setSessionState(result)
|
setSessionState(result)
|
||||||
|
|||||||
@ -48,6 +48,7 @@ export default function Login() {
|
|||||||
post({ url: '/api/login/v1.0/user', data: { loginId: res.data } }).then((response) => {
|
post({ url: '/api/login/v1.0/user', data: { loginId: res.data } }).then((response) => {
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
if (response) {
|
if (response) {
|
||||||
|
if (response.sessionId) Cookies.set('sessionId', response.sessionId)
|
||||||
const result = { ...response, storeLvl: response.groupId === '60000' ? '1' : '2', pwdInitYn: 'Y' }
|
const result = { ...response, storeLvl: response.groupId === '60000' ? '1' : '2', pwdInitYn: 'Y' }
|
||||||
setSession(result)
|
setSession(result)
|
||||||
setSessionState(result)
|
setSessionState(result)
|
||||||
@ -107,7 +108,7 @@ export default function Login() {
|
|||||||
if (res) {
|
if (res) {
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
if (res.data.result.resultCode === 'S') {
|
if (res.data.result.resultCode === 'S') {
|
||||||
Cookies.set('sessionId', res.data.sessionId)
|
if (res.data.sessionId) Cookies.set('sessionId', res.data.sessionId)
|
||||||
setSession(res.data.data)
|
setSession(res.data.data)
|
||||||
setSessionState(res.data.data)
|
setSessionState(res.data.data)
|
||||||
// ID SAVE 체크되어 있는 경우, 쿠키 저장
|
// ID SAVE 체크되어 있는 경우, 쿠키 저장
|
||||||
|
|||||||
38
src/hooks/useLogout.js
Normal file
38
src/hooks/useLogout.js
Normal 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 }
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user