diff --git a/src/app/Providers.tsx b/src/app/Providers.tsx index 8fff1eb..dc46845 100644 --- a/src/app/Providers.tsx +++ b/src/app/Providers.tsx @@ -4,10 +4,13 @@ import { CssBaseline, ThemeProvider } from '@mui/material'; import { createStore, Provider } from 'jotai'; import theme from '@/constants/theme'; +import useCurrentPath from '@/hooks/useCurrentPath'; const store = createStore(); const Providers = ({ children }: { children: React.ReactNode }) => { + useCurrentPath(); + return ( diff --git a/src/hooks/useCurrentPath.ts b/src/hooks/useCurrentPath.ts new file mode 100644 index 0000000..15b20df --- /dev/null +++ b/src/hooks/useCurrentPath.ts @@ -0,0 +1,22 @@ +'use client'; + +import { useEffect } from 'react'; + +import { useSetAtom } from 'jotai'; + +import { loginBackPathAtom } from '@/state/atom'; + +const useCurrentPath = () => { + const setCurrentPath = useSetAtom(loginBackPathAtom); + + useEffect(() => { + const excludedPaths = ['/login/oauth2/code/kakao']; + if (excludedPaths.includes(window.location.pathname)) { + return; + } + + setCurrentPath(window.location.pathname); + }, [setCurrentPath]); +}; + +export default useCurrentPath;