add checkauth
このコミットが含まれているのは:
コミット
e0eaeaf7c3
|
@ -7,7 +7,6 @@ export default function AlertStateMessage() {
|
||||||
const navigator = useNavigate();
|
const navigator = useNavigate();
|
||||||
const [_success, setSuccess] = useState('');
|
const [_success, setSuccess] = useState('');
|
||||||
const [_400error, set400Error] = useState('');
|
const [_400error, set400Error] = useState('');
|
||||||
const acc_type = pathname.split('/')[1];
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(state){
|
if(state){
|
||||||
|
@ -19,16 +18,6 @@ export default function AlertStateMessage() {
|
||||||
}
|
}
|
||||||
navigator(pathname);
|
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]);
|
}, [pathname]);
|
||||||
|
|
||||||
return (
|
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 { Outlet } from 'react-router-dom';
|
||||||
|
import CheckAuthenticate from '../component/check_auth';
|
||||||
import AlertStateMessage from '../component/alert_state_msg';
|
import AlertStateMessage from '../component/alert_state_msg';
|
||||||
|
|
||||||
const DashboardLayout = ({side}) => {
|
const DashboardLayout = ({side}) => {
|
||||||
|
@ -6,6 +7,7 @@ const DashboardLayout = ({side}) => {
|
||||||
return (
|
return (
|
||||||
<main className="l-container meeting-consent">
|
<main className="l-container meeting-consent">
|
||||||
<AlertStateMessage />
|
<AlertStateMessage />
|
||||||
|
<CheckAuthenticate />
|
||||||
<Outlet />
|
<Outlet />
|
||||||
{side}
|
{side}
|
||||||
</main>
|
</main>
|
||||||
|
|
新しいイシューから参照