diff --git a/src/pages/auth/login.tsx b/src/pages/auth/login.tsx index d879c98..1b5c4e6 100644 --- a/src/pages/auth/login.tsx +++ b/src/pages/auth/login.tsx @@ -1,15 +1,16 @@ import { yupResolver } from "@hookform/resolvers/yup"; import { LoadingButton } from "@mui/lab"; -import { AppBar, Box, Grid, Stack, Typography } from "@mui/material"; +import { Box, Stack, Typography } from "@mui/material"; import { PageID } from "codes/page"; import InputAlert from "components/form/InputAlert"; import { FormProvider, RHFTextField } from "components/hook-form"; import useAuth from "hooks/useAuth"; import useNavigateCustom from "hooks/useNavigateCustom"; import useSnackbarCustom from "hooks/useSnackbarCustom"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { getPath } from "routes/path"; +import { StoreId, setStore } from "storage/localstorage"; import * as Yup from "yup"; type FormProps = { @@ -56,6 +57,10 @@ export default function Login() { } }; + useEffect(() => { + setStore(StoreId.LOGIN_ROUTE, true); + }, []); + return ( diff --git a/src/pages/common/Page404.tsx b/src/pages/common/Page404.tsx index 7766d71..d87104d 100644 --- a/src/pages/common/Page404.tsx +++ b/src/pages/common/Page404.tsx @@ -1,5 +1,21 @@ import { Box } from "@mui/material"; +import { PageID } from "codes/page"; +import useNavigateCustom from "hooks/useNavigateCustom"; +import { useEffect } from "react"; +import { getPath } from "routes/path"; +import { StoreId, getStore } from "storage/localstorage"; export default function Page404() { + const { navigateWhenChanged } = useNavigateCustom(); + + // ログインページにアクセス経験ある場合は、ログインページへ遷移させる + useEffect(() => { + const canLoginRoute = !!getStore(StoreId.LOGIN_ROUTE); + + if (canLoginRoute) { + navigateWhenChanged(getPath(PageID.LOGIN)); + } + }, []); + return NotFound.; } diff --git a/src/storage/localstorage/index.ts b/src/storage/localstorage/index.ts new file mode 100644 index 0000000..1252a0f --- /dev/null +++ b/src/storage/localstorage/index.ts @@ -0,0 +1,18 @@ +let id = 0; +export const StoreId = { + LOGIN_ROUTE: "LOGIN_ROUTE", +} as const; +export type StoreId = (typeof StoreId)[keyof typeof StoreId]; + +export const getStore = (id: StoreId): string | null => { + return localStorage.getItem(id); +}; +export const setStore = (id: StoreId, data: any) => { + localStorage.setItem(id, data); +}; +export const removeStore = (id: StoreId) => { + localStorage.removeItem(id); +}; +export const clearStore = () => { + localStorage.clear(); +};