Hello creators ๐
240815-์ธ์์ธ๊ณ์ค๋น-์๋๋ฒ๋ ์ฑํ ๋ณธ๋ฌธ
[ํ๋ก ํธ์๋(FE) ๊ฐ๋ฐ] (feat. ์ฃผ๋์ด)/TIL
240815-์ธ์์ธ๊ณ์ค๋น-์๋๋ฒ๋ ์ฑํ
๋ถ์๋งค๋_HA 2024. 8. 15. 22:34728x90
๋ฐ์ํ
TODO
- ์ธ์ ์ธ๊ณ ์ค๋น
- ๋น๋ ํฐ์ง๋๊ฑฐ ์์
- SecureRoute ์ ๋ํด์ ๊ณต๋ถ
- ์ฑํ ๋ฐฉ ์์ฑํ๊ฒ ํ๊ธฐ โญโญโญโญโญ
- ํฌ๋กค๋ง ๋ด์ด ๋ต๋ณํ๊ฒ ํ๊ธฐ โญโญโญโญโญ
DO
์ธ์ ์ธ๊ณ ์ค๋น
_test\์ธ์์ธ๊ณ ๋ฏธํ ๊ด๋ จ\240814-์ธ์์ธ๊ณ์ค๋น.md
SecureRoute ์ด๊ฑธ๋ก ํ ํฐ ์ฌ๋ถ ํ๋จํด์ ๋ฆฌ๋๋ ์ โญโญโญโญโญ
import { ComponentProps, createElement, FC } from "react";
import { Redirect, Route } from "react-router-dom";
import { getAccessToken } from "@/src/lib/jwt";
const SecureRoute: FC<ComponentProps<typeof Route>> = ({ component = "div", ...rest }) => {
return (
<Route
{...rest}
render={({ location }) => {
if (!!getAccessToken()) {
return createElement(component);
}
// ์์ธ์ค ํ ํฐ์ด ์์ผ๋ฉด ๋ก๊ทธ์ธ ํ๋ฉด์ผ๋ก ๋ฆฌ๋ค์ด๋ ํธ
return (
<Redirect
to={{
pathname: "/login",
state: { from: location },
}}
/>
);
}}
/>
);
};
export default SecureRoute;
์ฑํ ๋ฐฉ ์์ฑํ๊ฒ ํ๊ธฐ โญโญโญโญโญ
- ์ถ์ฒ : C:\Users\nextinnovation\Desktop\NextInnonavtion\projects\antschool\antschool-web-admin\app\chatTest\page.tsx
728x90
๋ฐ์ํ
'[ํ๋ก ํธ์๋(FE) ๊ฐ๋ฐ] (feat. ์ฃผ๋์ด) > TIL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Comments