-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
248 additions
and
52 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 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
64 changes: 64 additions & 0 deletions
64
judo-ui-react/src/main/resources/actor/src/auth/AuthErrorBox.tsx.hbs
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,64 @@ | ||
import { useCallback } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
{{# if application.authentication }} | ||
import { useAuth } from 'react-oidc-context'; | ||
{{/ if }} | ||
import Typography from '@mui/material/Typography'; | ||
import Box from '@mui/material/Box'; | ||
import Button from '@mui/material/Button'; | ||
|
||
export interface AuthErrorBoxProps { | ||
title: string; | ||
message: string; | ||
} | ||
|
||
export function AuthErrorBox({ title, message }: AuthErrorBoxProps) { | ||
const { t } = useTranslation(); | ||
{{# if application.authentication }} | ||
const { signoutRedirect, isAuthenticated } = useAuth(); | ||
const doLogout = useCallback(() => { | ||
const redirectUrl = window.location.href.split('#')[0]; | ||
signoutRedirect({ | ||
post_logout_redirect_uri: redirectUrl, | ||
}); | ||
}, [isAuthenticated]); | ||
{{/ if }} | ||
|
||
return ( | ||
<Box | ||
display="flex" | ||
flexDirection="column" | ||
justifyContent="center" | ||
alignItems="center" | ||
textAlign="center" | ||
sx={ { | ||
backgroundColor: '#f8f9fa', | ||
borderRadius: '8px', | ||
padding: '2rem', | ||
boxShadow: '0px 4px 10px rgba(0, 0, 0, 0.1)', | ||
} } | ||
> | ||
<Typography variant="h4" color="error" gutterBottom> | ||
{title} | ||
</Typography> | ||
<Typography variant="body1" color="textSecondary" gutterBottom> | ||
{message} | ||
</Typography> | ||
{{# if application.authentication }} | ||
<Box display={'flex'}> | ||
<Button variant="text" color="primary" onClick={doLogout} sx={ { marginTop: '1rem' } }> | ||
{t('judo.security.logout', { defaultValue: 'Logout' })} | ||
</Button> | ||
<Button | ||
variant="contained" | ||
color="primary" | ||
onClick={() => window.location.reload()} | ||
sx={ { marginTop: '1rem' } } | ||
> | ||
{t('judo.error.boundary.reload-page', { defaultValue: 'Reload Page' })} | ||
</Button> | ||
</Box> | ||
{{/ if }} | ||
</Box> | ||
); | ||
} |
22 changes: 22 additions & 0 deletions
22
judo-ui-react/src/main/resources/actor/src/auth/AuthProxyComponent.tsx.hbs
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,22 @@ | ||
import type { FC, ReactNode } from 'react'; | ||
{{# if application.authentication }} | ||
import { useTrackComponent } from '@pandino/react-hooks'; | ||
{{/ if }} | ||
|
||
interface AuthProxyComponentProps { | ||
filter: string; | ||
children?: ReactNode; | ||
[prop: string]: any; | ||
} | ||
|
||
export const AuthProxyComponent: FC<AuthProxyComponentProps> = ({ filter, children, ...other }) => { | ||
{{# if application.authentication }} | ||
const ExternalComponent = useTrackComponent<any>(filter); | ||
|
||
if (ExternalComponent) { | ||
return <ExternalComponent {...other} children={children} />; | ||
} | ||
{{/ if }} | ||
|
||
return <>{children}</>; | ||
}; |
11 changes: 11 additions & 0 deletions
11
judo-ui-react/src/main/resources/actor/src/auth/constants.ts.hbs
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,6 +1,17 @@ | ||
{{> fragment.header.hbs }} | ||
|
||
{{# if application.authentication }} | ||
import { type ReactNode } from 'react'; | ||
import { type {{ classDataName application.principal 'Stored' }} } from '~/services/data-api/model/{{ classDataName application.principal '' }}'; | ||
{{/ if }} | ||
import { endWithSlash } from '../utilities'; | ||
|
||
const base = document.querySelector('base')!.getAttribute('href') as string; | ||
export const appBaseUri = endWithSlash(window.location.origin + base); | ||
{{# if application.authentication }} | ||
export const ACCESS_FILTER_COMPONENT_INTERFACE_KEY = 'AccessFilterComponent'; | ||
export interface AccessFilterComponentProps { | ||
principal: {{ classDataName application.principal 'Stored' }}; | ||
children?: ReactNode; | ||
} | ||
{{/ if }} |
2 changes: 2 additions & 0 deletions
2
judo-ui-react/src/main/resources/actor/src/auth/index.tsx.hbs
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,6 +1,8 @@ | ||
{{> fragment.header.hbs }} | ||
|
||
export * from './Auth'; | ||
export * from './AuthErrorBox'; | ||
export * from './AuthProxyComponent'; | ||
export * from './axiosInterceptor'; | ||
export * from './constants'; | ||
export * from './principal-context'; |
112 changes: 63 additions & 49 deletions
112
judo-ui-react/src/main/resources/actor/src/auth/principal-context.tsx.hbs
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