Add token valification unit test

This commit is contained in:
Takeshi Kimata
2024-06-01 20:03:01 +09:00
parent 09a7e08667
commit d987d822c4

View File

@@ -75,7 +75,20 @@ const TokenProvider = ({ toastMessages, locale, children }: TokenProps) => {
}, []); }, []);
useEffect(() => { useEffect(() => {
tokenCheckSignInPage(token, pathname); if (!hasRestoreFinished) {
return;
}
const ret = tokenCheckSignInPage(token, pathname);
if (!ret.ok) {
if (ret.reason === 'notoken') {
toastContext.showToast(toastMessages.needSignedIn, 'error');
} else if (ret.reason === 'expired') {
toastContext.showToast(toastMessages.sessionExpired, 'error');
}
router.push(ret.redirectPath, { locale: locale });
}
}, [pathname, hasRestoreFinished]); }, [pathname, hasRestoreFinished]);
return <TokenContext.Provider value={tokenContext}>{children}</TokenContext.Provider>; return <TokenContext.Provider value={tokenContext}>{children}</TokenContext.Provider>;