Fix authenticated routing issues
This commit is contained in:
18
src/components/Routes/AuthRoute.jsx
Normal file
18
src/components/Routes/AuthRoute.jsx
Normal 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} />;
|
||||
}
|
||||
Reference in New Issue
Block a user