Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
thecybernanny-webapp
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
asranov0003
thecybernanny-webapp
Commits
a0584e8a
Commit
a0584e8a
authored
Jul 01, 2025
by
asranov0003
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: router and protected route logic
parent
0c26337e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
13 deletions
+24
-13
ProtectedRoute.tsx
src/routes/ProtectedRoute.tsx
+7
-3
Router.tsx
src/routes/Router.tsx
+17
-10
No files found.
src/routes/ProtectedRoute.tsx
View file @
a0584e8a
...
...
@@ -12,13 +12,17 @@ const ProtectedRoute: React.FC<ProtectedRouteProps> = ({
redirectTo
,
})
=>
{
const
isAuthenticated
=
!!
localStorage
.
getItem
(
`token-
${
TG_USER_ID
}
`
);
const
p
incode
=
!!
sessionStorage
.
getItem
(
`pincode-
${
TG_USER_ID
}
`
);
const
hasP
incode
=
!!
sessionStorage
.
getItem
(
`pincode-
${
TG_USER_ID
}
`
);
if
(
isAuthenticated
&&
!
pincode
)
{
if
(
!
isAuthenticated
)
{
return
<
Navigate
to=
{
redirectTo
}
/>;
}
if
(
!
hasPincode
)
{
return
<
Navigate
to=
"/pincode"
/>;
}
return
isAuthenticated
?
element
:
<
Navigate
to=
{
redirectTo
}
/>
;
return
element
;
};
export
default
ProtectedRoute
;
src/routes/Router.tsx
View file @
a0584e8a
...
...
@@ -22,26 +22,33 @@ const Router: React.FC = () => {
const
router
=
createBrowserRouter
([
{
path
:
"/"
,
element
:
isAuthenticated
&&
<
Navigate
to=
{
"/home"
}
/>,
path
:
"/auth"
,
children
:
[
{
path
:
"/auth/login"
,
element
:
<
Login
/>,
index
:
true
,
element
:
isAuthenticated
?
(
<
Navigate
to=
"/home"
/>
)
:
(
<
Navigate
to=
"/auth/login"
/>
),
},
{
path
:
"login"
,
element
:
isAuthenticated
?
<
Navigate
to=
"/home"
/>
:
<
Login
/>,
},
{
path
:
"
/auth/
register"
,
element
:
<
Register
/>,
path
:
"register"
,
element
:
isAuthenticated
?
<
Navigate
to=
"/home"
/>
:
<
Register
/>,
},
{
path
:
"
/auth/
recover"
,
element
:
<
Recover
/>,
path
:
"recover"
,
element
:
isAuthenticated
?
<
Navigate
to=
"/home"
/>
:
<
Recover
/>,
},
],
},
{
path
:
"/"
,
element
:
<
ProtectedRoute
element=
{
<
Layout
/>
}
redirectTo=
"/"
/>,
element
:
<
ProtectedRoute
element=
{
<
Layout
/>
}
redirectTo=
"/
auth/login
"
/>,
children
:
[
{
path
:
"home"
,
...
...
@@ -63,7 +70,7 @@ const Router: React.FC = () => {
},
{
path
:
"/pincode"
,
element
:
<
Pincode
/>,
element
:
isAuthenticated
?
<
Pincode
/>
:
<
Navigate
to=
"/auth/login"
/>,
},
{
path
:
"*"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment