-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from potenday-project:로그인/로그아웃-핸들러-개선
로그인/로그아웃-핸들러-개선
- Loading branch information
Showing
15 changed files
with
81 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import axios from "@/libs/axios"; | ||
import getTokenFromLocalStorage from "@/utils/getTokenFromLocalStorage"; | ||
|
||
const useAxiosPrivate = () => { | ||
axios.interceptors.request.use( | ||
(config) => { | ||
if (config.headers) { | ||
config.headers.Authorization = getTokenFromLocalStorage(); | ||
} | ||
return config; | ||
}, | ||
(error) => Promise.reject(error) | ||
); | ||
return axios; | ||
}; | ||
|
||
export default useAxiosPrivate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import HOME from "@/const/clientPath"; | ||
import { LOGOUT_BFF } from "@/const/serverPath"; | ||
import { axiosBff } from "@/libs/axios"; | ||
import { useGlobalSnackbarStore } from "@/store/useGlobalSnackbarStore"; | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
const useLogoutMutation = () => { | ||
const router = useRouter(); | ||
const queryClient = useQueryClient(); | ||
|
||
const fireToast = useGlobalSnackbarStore((state) => state.fireToast); | ||
|
||
return useMutation({ | ||
mutationFn: logoutFn, | ||
onSuccess: () => { | ||
localStorage.removeItem("accessToken"); | ||
queryClient.removeQueries(); | ||
router.push(HOME); | ||
fireToast("로그아웃이 완료되었습니다"); | ||
}, | ||
}); | ||
}; | ||
const logoutFn = () => axiosBff.post(LOGOUT_BFF); | ||
|
||
export default useLogoutMutation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters