add checkauth
このコミットが含まれているのは:
コミット
e0eaeaf7c3
|
@ -7,7 +7,6 @@ export default function AlertStateMessage() {
|
|||
const navigator = useNavigate();
|
||||
const [_success, setSuccess] = useState('');
|
||||
const [_400error, set400Error] = useState('');
|
||||
const acc_type = pathname.split('/')[1];
|
||||
|
||||
useEffect(() => {
|
||||
if(state){
|
||||
|
@ -19,16 +18,6 @@ export default function AlertStateMessage() {
|
|||
}
|
||||
navigator(pathname);
|
||||
}
|
||||
|
||||
let token = localStorage.getItem(`${acc_type}_token`);
|
||||
if(token){
|
||||
token = JSON.parse(token);
|
||||
if(token.from_login) {
|
||||
setSuccess('ログインに成功しました');
|
||||
token.from_login = false;
|
||||
localStorage.setItem(`${acc_type}_token`, JSON.stringify(token));
|
||||
}
|
||||
}
|
||||
}, [pathname]);
|
||||
|
||||
return (
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
import { useEffect, useState } from "react";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import Alert from './alert';
|
||||
|
||||
export default function CheckAuthenticate() {
|
||||
const { pathname } = useLocation();
|
||||
const [_success, setSuccess] = useState('');
|
||||
const navigator = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
const acc_type = pathname.split('/')[1];
|
||||
|
||||
let token = localStorage.getItem(`${acc_type}_token`);
|
||||
if(!token){
|
||||
navigator(`/${acc_type}/login`);
|
||||
}
|
||||
else{
|
||||
token = JSON.parse(token);
|
||||
if(token.from_login) {
|
||||
setSuccess('ログインに成功しました');
|
||||
token.from_login = false;
|
||||
localStorage.setItem(`${acc_type}_token`, JSON.stringify(token));
|
||||
}
|
||||
}
|
||||
}, [pathname]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{ _success ? <Alert type="success" hide={()=>setSuccess('')}>{ _success }</Alert> : null}
|
||||
</>
|
||||
);
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import { Outlet } from 'react-router-dom';
|
||||
import CheckAuthenticate from '../component/check_auth';
|
||||
import AlertStateMessage from '../component/alert_state_msg';
|
||||
|
||||
const DashboardLayout = ({side}) => {
|
||||
|
@ -6,6 +7,7 @@ const DashboardLayout = ({side}) => {
|
|||
return (
|
||||
<main className="l-container meeting-consent">
|
||||
<AlertStateMessage />
|
||||
<CheckAuthenticate />
|
||||
<Outlet />
|
||||
{side}
|
||||
</main>
|
||||
|
|
新しいイシューから参照