๋ฐ˜์‘ํ˜•
250x250
Recent Posts
ยซ   2024/12   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Hello creators ๐Ÿ™Œ

240815-์ธ์ˆ˜์ธ๊ณ„์ค€๋น„-์ƒŒ๋“œ๋ฒ„๋“œ ์ฑ„ํŒ… ๋ณธ๋ฌธ

[ํ”„๋ก ํŠธ์—”๋“œ(FE) ๊ฐœ๋ฐœ] (feat. ์ฃผ๋‹ˆ์–ด)/TIL

240815-์ธ์ˆ˜์ธ๊ณ„์ค€๋น„-์ƒŒ๋“œ๋ฒ„๋“œ ์ฑ„ํŒ…

๋ถ€์‹œ๋งค๋‚˜_HA 2024. 8. 15. 22:34
728x90
๋ฐ˜์‘ํ˜•

TODO

  1. ์ธ์ˆ˜ ์ธ๊ณ„ ์ค€๋น„
  2. ๋นŒ๋“œ ํ„ฐ์ง€๋Š”๊ฑฐ ์ˆ˜์ •
  3. SecureRoute ์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€
  4. ์ฑ„ํŒ…๋ฐฉ ์ƒ์„ฑํ•˜๊ฒŒ ํ•˜๊ธฐ โญโญโญโญโญ
  5. ํฌ๋กค๋ง ๋ด‡์ด ๋‹ต๋ณ€ํ•˜๊ฒŒ ํ•˜๊ธฐ โญโญโญโญโญ

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
๋ฐ˜์‘ํ˜•
Comments