Skip to content

Commit

Permalink
[feat] Automatically route to login page when token value is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
WooHyunKing committed Sep 5, 2023
1 parent 8f9c723 commit 8ab61c3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/Router.tsx
Expand Up @@ -53,7 +53,6 @@ export default Router;

const TopContainer = styled.div`
display: flex;
width: 1440px;
height: 900px;
border: 1px solid black;
width: 100%;
height: 100%;
`;
4 changes: 2 additions & 2 deletions src/components/container/Container.tsx
Expand Up @@ -4,6 +4,6 @@ import styled from "styled-components";
export const Container = styled.div`
display: flex;
flex-direction: column;
width: 1440px;
height: 809px;
width: 100%;
height: 100%;
`;
8 changes: 7 additions & 1 deletion src/pages/account/login/Login.tsx
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { useRecoilState } from "recoil";
import styled from "styled-components";
Expand All @@ -17,6 +17,12 @@ const Login = () => {
const [circleList, setCircleList] = useRecoilState(studentCircleListAtom);
const navigate = useNavigate();

useEffect(() => {
if (sessionStorage.getItem("token") === undefined) {
navigate("/login");
}
}, []);

const loginPost = async (id: string, password: string, studentId: string) => {
const response = await axios.post(
"/login",
Expand Down
14 changes: 12 additions & 2 deletions src/pages/main/Main.tsx
@@ -1,9 +1,19 @@
import React from "react";
import { Outlet } from "react-router-dom";
import React, { useEffect } from "react";
import { Outlet, useNavigate } from "react-router-dom";
import { Container } from "../../components/container/Container";
import Header from "../../components/header/Header";

const Main = () => {
const navigate = useNavigate();

useEffect(() => {
if (sessionStorage.getItem("token") === undefined) {
navigate("/login");
} else {
navigate("/member-club");
}
}, []);

return (
<>
{/* <MenuBar /> */}
Expand Down

0 comments on commit 8ab61c3

Please sign in to comment.