-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: index and login-redirect pages follow redirection rules
- Loading branch information
1 parent
1dc9230
commit 02496e5
Showing
22 changed files
with
355 additions
and
151 deletions.
There are no files selected for viewing
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,56 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { useRouter } from "next/router"; | ||
import type { SessionExpiryHandlerQuery } from "__generated__/SessionExpiryHandlerQuery.graphql"; | ||
import { graphql, fetchQuery, useRelayEnvironment } from "react-relay"; | ||
import { SessionTimeoutHandler, SessionRefresher } from "@bcgov-cas/sso-react"; | ||
|
||
const sessionQuery = graphql` | ||
query SessionExpiryHandlerQuery { | ||
session { | ||
__typename | ||
} | ||
} | ||
`; | ||
|
||
const SessionExpiryHandler: React.FC = () => { | ||
const [hasSession, setHasSession] = useState(false); | ||
|
||
const router = useRouter(); | ||
const environment = useRelayEnvironment(); | ||
|
||
useEffect(() => { | ||
const checkSessionAndGroups = async () => { | ||
const { session } = await fetchQuery<SessionExpiryHandlerQuery>( | ||
environment, | ||
sessionQuery, | ||
{} | ||
).toPromise(); | ||
setHasSession(!!session); | ||
}; | ||
checkSessionAndGroups(); | ||
// This effect only needs to be run once on mount, even if the relay environment changes | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
const handleSessionExpired = () => { | ||
router.push({ | ||
pathname: "/login-redirect", | ||
query: { | ||
redirectTo: router.asPath, | ||
sessionIdled: true, | ||
}, | ||
}); | ||
}; | ||
|
||
if (hasSession) | ||
return ( | ||
<> | ||
<SessionRefresher /> | ||
<SessionTimeoutHandler onSessionExpired={handleSessionExpired} /> | ||
</> | ||
); | ||
|
||
return null; | ||
}; | ||
|
||
export default SessionExpiryHandler; |
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 |
---|---|---|
@@ -1,14 +1,8 @@ | ||
export const GUEST = "Guest"; | ||
export const NON_IDIR_USER = "NON_IDIR_USER"; | ||
export const UNAUTHORIZED_IDIR_USER = "UNAUTHORIZED_IDIR_USER"; | ||
export const REALM_ADMINISTRATOR = "Realm Administrator"; | ||
|
||
export const CIF_INTERNAL = "cif_internal"; | ||
|
||
export const CIF_EXTERNAL = "cif_external"; | ||
|
||
export const CIF_ADMIN = "cif_admin"; | ||
|
||
|
||
export const ADMIN_ROLES = [REALM_ADMINISTRATOR, CIF_ADMIN]; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
[ | ||
{ | ||
"routePaths": ["/", "/login-redirect", "/login"], | ||
"routePaths": ["/", "/login-redirect"], | ||
"isProtected": false | ||
}, | ||
{ | ||
"routePaths": ["/admin(.*)"], | ||
"isProtected": true, | ||
"allowedRoles": ["cif_admin", "Realm Administrator"] | ||
}, | ||
{ | ||
"routePaths": ["/internal"], | ||
"isProtected": true, | ||
"allowedRoles": ["cif_internal"] | ||
}, | ||
{ | ||
"routePaths": ["/internal/(.*)"], | ||
"isProtected": true, | ||
"allowedRoles": ["cif_internal", "cif_admin", "Realm Administrator"] | ||
} | ||
] |
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
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.
Oops, something went wrong.