Fix authenticated routing issues

This commit is contained in:
jwu-fisker
2021-01-06 10:35:30 -08:00
parent 44c56df2c0
commit 3d50e8c45a
4 changed files with 60 additions and 29 deletions

View File

@@ -0,0 +1,18 @@
import React from 'react';
import { Redirect, Route } from 'react-router-dom';
export const TYPES = {
PUBLIC: 0,
GUEST: 1,
PROTECTED: 2,
};
export const AuthRoute = ({ token, type, ...others }) => {
if (!token && type === TYPES.PROTECTED) {
return <Redirect to="/" />;
}
else if (token && type === TYPES.GUEST) {
return <Redirect to="/home" />;
}
return <Route render {...others} />;
}