✨feat: Redirect to console if logged in and accessing auth pages
This commit introduces a new component `AuthRedirect` which checks if a user is already logged in. If the user is logged in and attempts to access the /login or /register pages, they will be redirected to the /console page. Otherwise, the respective authentication form (Login or Register) will be rendered. The `App.js` file has been updated to utilize this new `AuthRedirect` component for the /login and /register routes.
This commit is contained in:
14
web/src/components/AuthRedirect.js
Normal file
14
web/src/components/AuthRedirect.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import React from 'react';
|
||||
import { Navigate } from 'react-router-dom';
|
||||
|
||||
const AuthRedirect = ({ children }) => {
|
||||
const user = localStorage.getItem('user');
|
||||
|
||||
if (user) {
|
||||
return <Navigate to="/console" replace />;
|
||||
}
|
||||
|
||||
return children;
|
||||
};
|
||||
|
||||
export default AuthRedirect;
|
||||
Reference in New Issue
Block a user