feat: remove auth, store, redux, and axios from template
Agent-Logs-Url: https://github.com/zihluwang/delta-force-firearm-modification-codes/sessions/3477dccf-d002-4dda-ad39-4768da36bb9e Co-authored-by: zihluwang <47817169+zihluwang@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
5d44e24c95
commit
b3caeb8ce5
@@ -1,40 +0,0 @@
|
||||
import { Navigate, Outlet, useLocation } from "react-router"
|
||||
import { useAppSelector } from "@/store"
|
||||
|
||||
/**
|
||||
* Renders child routes if the user is unauthenticated, otherwise redirects authenticated users to
|
||||
* the root path.
|
||||
*
|
||||
* This component's logic allows unauthenticated users to access nested routes rendered
|
||||
* via `Outlet`. Conversely, if a user is authenticated, they are redirected to the application's
|
||||
* root path (`""`). This behaviour is inverse to the typical implementation of a 'protected route',
|
||||
* which usually grants access to authenticated users and redirects unauthenticated users to a
|
||||
* login page.
|
||||
*/
|
||||
export default function ProtectedRoute() {
|
||||
/**
|
||||
* Retrieves the authentication status from the Redux store.
|
||||
*/
|
||||
const isAuthenticated = useAppSelector((state) => state.auth.isAuthenticated)
|
||||
|
||||
/**
|
||||
* Retrieves the current location object from React Router.
|
||||
*/
|
||||
const location = useLocation()
|
||||
|
||||
if (isAuthenticated) {
|
||||
/**
|
||||
* Redirects authenticated users to the application's root path (`""`).
|
||||
*
|
||||
* The redirection includes the current location's state, allowing the
|
||||
* target route to know where the user was redirected from. The
|
||||
* `replace` prop ensures the current history entry is replaced.
|
||||
*/
|
||||
return <Navigate to="" state={{ from: location }} replace />
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the child routes if the user is unauthenticated.
|
||||
*/
|
||||
return <Outlet />
|
||||
}
|
||||
Reference in New Issue
Block a user