-
Notifications
You must be signed in to change notification settings - Fork 0
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 #11 from team-GDGline/feat/error
feat: accessToken 없을 시에 loingPage로 navigate 구현
- Loading branch information
Showing
4 changed files
with
66 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL; | ||
|
||
export const ACCESS_TOKEN = "accessToken"; | ||
export const REFRESH_TOKEN = "refreshToken"; |
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,24 @@ | ||
import {Outlet, useLocation, useNavigate} from "react-router-dom"; | ||
|
||
import { useEffect } from "react"; | ||
const TokenRouter = () => { | ||
|
||
const location = useLocation(); | ||
const navigate = useNavigate(); | ||
const isAuthPath = location.pathname === "/login" || location.pathname === "/signup"; | ||
|
||
|
||
useEffect(() => { | ||
if(!localStorage.getItem("accessToken") && !isAuthPath){ | ||
navigate("/login"); | ||
} | ||
|
||
}, [location.pathname, isAuthPath, navigate]); | ||
return ( | ||
<div> | ||
<Outlet /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TokenRouter; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export const RouterPath = { | ||
token: "", | ||
root: "/", | ||
start: "/", | ||
login: "/login", | ||
|