-
Notifications
You must be signed in to change notification settings - Fork 0
JNG-5697 On module change when different user have valid key invalida… #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,34 @@ import type { ReactNode } from 'react'; | |
| import { useEffect } from 'react'; | ||
| import { useAuth, hasAuthParams } from 'react-oidc-context'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { useSearchParams } from 'react-router-dom'; | ||
| {{# if application.authentication }} | ||
| import { getUser, clearSecurityStorage } from '../auth'; | ||
| {{/ if }} | ||
|
|
||
| export const Auth = ({ children }: { children?: ReactNode }) => { | ||
| const { isAuthenticated, isLoading, activeNavigator, signinRedirect, events } = useAuth(); | ||
| const { t } = useTranslation(); | ||
|
|
||
| {{# if application.authentication }} | ||
| // check current token's user name with given parameter (when defined) | ||
| useEffect(() => { | ||
| const search = window.location.search; | ||
| const params = new URLSearchParams(search); | ||
| const forcedUser = params.get('user'); | ||
|
|
||
| if (forcedUser != null) { | ||
| // Get current user name from token | ||
| const { profile } = getUser(); | ||
| const tokenUser = profile?.preferred_username; | ||
| if (tokenUser != null && tokenUser === forcedUser) { | ||
| clearSecurityStorage(); | ||
| window.location.reload(); | ||
| } | ||
| } | ||
| }, [useSearchParams, getUser]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| {{/ if }} | ||
|
|
||
| // automatically sign-in | ||
| useEffect(() => { | ||
| if (!hasAuthParams() && !isAuthenticated && !activeNavigator && !isLoading) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| {{> fragment.header.hbs }} | ||
|
|
||
| import { clearSecurityStorage } from '~/auth'; | ||
| import { clearSecurityStorage, getUser } from '~/auth'; | ||
| import type { HandleApplicationChange } from './interfaces'; | ||
|
|
||
| export const changeApplication: HandleApplicationChange = (applicationKey: string) => { | ||
| const { profile } = getUser(); | ||
| const tokenUser = profile?.preferred_username; | ||
| clearSecurityStorage(); | ||
| const { origin } = window.location; | ||
| window.location.href = origin + '/' + applicationKey; | ||
| window.location.href = origin + '/' + applicationKey + "?user=" + tokenUser ; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
?usersearch param should be removed before we reload I think since we won't need it any more.