-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from jakkemomo/general_fixes
fix: add RouteGuard, change route-access logic and some general fixes
- Loading branch information
Showing
32 changed files
with
370 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useMyDetailsQuery } from "@/entities/profile/api/profileApi"; | ||
import { ReactElement } from "react"; | ||
import { Navigate } from "react-router-dom"; | ||
|
||
interface GuestGuardProps { | ||
children: ReactElement; | ||
type: 'auth' | 'guest'; | ||
} | ||
|
||
function RouteGuard({ children, type }: GuestGuardProps) { | ||
const { | ||
isError, | ||
isSuccess | ||
} = useMyDetailsQuery(); | ||
|
||
if (isError && type === 'guest') { | ||
return <Navigate to="/" replace /> | ||
} | ||
|
||
if (isError && type === 'auth') { | ||
return children; | ||
} | ||
|
||
if (isSuccess && type === 'auth') { | ||
return <Navigate to="/" replace /> | ||
} | ||
|
||
if (isSuccess) { | ||
return children; | ||
} | ||
} | ||
|
||
export default RouteGuard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.