-
Notifications
You must be signed in to change notification settings - Fork 8
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 #635 from etn-ccis/feature/update-example-with-log…
…in-callback Updated example with login callback
- Loading branch information
Showing
6 changed files
with
171 additions
and
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import React, { useCallback, useEffect } from 'react'; | ||
import { | ||
AuthContextProvider, | ||
OktaAuthContextProvider, | ||
ContactSupportScreen, | ||
ReactRouterAuthGuard, | ||
ReactRouterGuestGuard, | ||
ForgotPasswordScreen, | ||
RegistrationContextProvider, | ||
ResetPasswordScreen, | ||
RegistrationWorkflow, | ||
} from '@brightlayer-ui/react-auth-workflow'; | ||
import { useApp } from '../contexts/AppContextProvider'; | ||
import { useNavigate } from 'react-router'; | ||
import { ProjectAuthUIActions } from '../actions/AuthUIActions'; | ||
import { Navigate, Outlet, Route, Routes, To } from 'react-router-dom'; | ||
import { ProjectRegistrationUIActions } from '../actions/RegistrationUIActions'; | ||
import { routes } from './Routing'; | ||
import { ExampleHome } from '../screens/ExampleHome'; | ||
import i18nAppInstance from '../translations/i18n'; | ||
import { ChangePassword } from '../components/ChangePassword'; | ||
import { OktaLogin } from '../screens/OktaRedirectLogin'; | ||
import { useOktaAuth, LoginCallback } from '@okta/okta-react'; | ||
|
||
export const MainRouter: React.FC = () => { | ||
const navigation = useNavigate(); | ||
const app = useApp(); | ||
const { email, rememberMe } = app.loginData; | ||
const navigate = useCallback((destination: -1 | string) => { | ||
navigation(destination as To); | ||
}, []); | ||
const { authState } = useOktaAuth(); | ||
|
||
const { setIsAuthenticated } = useApp(); | ||
|
||
useEffect(() => { | ||
if (authState && authState.isAuthenticated) { | ||
setIsAuthenticated(true); | ||
} else { | ||
setIsAuthenticated(false); | ||
} | ||
}, [authState, setIsAuthenticated]); | ||
|
||
return ( | ||
<Routes> | ||
{/* AUTH ROUTES */} | ||
<Route | ||
element={ | ||
<AuthContextProvider | ||
actions={ProjectAuthUIActions(app)} | ||
language={app.language} | ||
navigate={navigate} | ||
routeConfig={routes} | ||
i18n={i18nAppInstance} | ||
rememberMeDetails={{ email: rememberMe ? email : '', rememberMe: rememberMe }} | ||
> | ||
<Outlet /> | ||
</AuthContextProvider> | ||
} | ||
> | ||
<Route | ||
path={'/login'} | ||
element={ | ||
<ReactRouterGuestGuard isAuthenticated={app.isAuthenticated} fallBackUrl={'/'}> | ||
<OktaAuthContextProvider | ||
language={app.language} | ||
navigate={navigate} | ||
routeConfig={routes} | ||
i18n={i18nAppInstance} | ||
> | ||
<OktaLogin /> | ||
</OktaAuthContextProvider> | ||
</ReactRouterGuestGuard> | ||
} | ||
/> | ||
<Route | ||
path={'/forgot-password'} | ||
element={ | ||
<ReactRouterGuestGuard isAuthenticated={app.isAuthenticated} fallBackUrl={'/'}> | ||
<ForgotPasswordScreen /> | ||
</ReactRouterGuestGuard> | ||
} | ||
/> | ||
<Route | ||
path={'/contact-support'} | ||
element={ | ||
<ReactRouterGuestGuard isAuthenticated={app.isAuthenticated} fallBackUrl={'/'}> | ||
<ContactSupportScreen /> | ||
</ReactRouterGuestGuard> | ||
} | ||
/> | ||
<Route | ||
path={'/reset-password'} | ||
element={ | ||
<ReactRouterGuestGuard isAuthenticated={app.isAuthenticated} fallBackUrl={'/'}> | ||
<ResetPasswordScreen /> | ||
</ReactRouterGuestGuard> | ||
} | ||
/> | ||
{/* USER APPLICATION ROUTES */} | ||
<Route | ||
element={ | ||
<> | ||
<Outlet /> | ||
{app.showChangePasswordDialog && <ChangePassword />} | ||
</> | ||
} | ||
> | ||
<Route | ||
path={'/login/callback'} | ||
element={ | ||
<ReactRouterGuestGuard isAuthenticated={app.isAuthenticated} fallBackUrl={'/'}> | ||
<LoginCallback /> | ||
</ReactRouterGuestGuard> | ||
} | ||
/> | ||
<Route | ||
path={'/homepage'} | ||
element={ | ||
<ReactRouterAuthGuard isAuthenticated={app.isAuthenticated} fallBackUrl={'/login'}> | ||
<ExampleHome /> | ||
</ReactRouterAuthGuard> | ||
} | ||
/> | ||
<Route path={'/'} element={<Navigate to={'/homepage'} replace />} /> | ||
</Route> | ||
<Route | ||
path={'*'} | ||
element={ | ||
<ReactRouterAuthGuard isAuthenticated={app.isAuthenticated} fallBackUrl={'/login'}> | ||
<Navigate to={'/login'} /> | ||
</ReactRouterAuthGuard> | ||
} | ||
/> | ||
</Route> | ||
{/* REGISTRATION ROUTES */} | ||
<Route | ||
element={ | ||
<RegistrationContextProvider | ||
language={app.language} | ||
routeConfig={routes} | ||
navigate={navigate} | ||
actions={ProjectRegistrationUIActions()} | ||
i18n={i18nAppInstance} | ||
> | ||
<Outlet /> | ||
</RegistrationContextProvider> | ||
} | ||
> | ||
<Route path={'/self-registration'} element={<RegistrationWorkflow />} /> | ||
<Route path={'/register-by-invite'} element={<RegistrationWorkflow isInviteRegistration />} /> | ||
</Route> | ||
</Routes> | ||
); | ||
}; |
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,6 +1,6 @@ | ||
{ | ||
"name": "@brightlayer-ui/react-auth-workflow", | ||
"version": "5.0.0-beta.2", | ||
"version": "5.0.0", | ||
"author": "Brightlayer UI <[email protected]> (https://github.com/brightlayer-ui)", | ||
"license": "BSD-3-Clause", | ||
"description": "Re-usable workflow components for Authentication and Registration within Eaton applications.", | ||
|
@@ -37,6 +37,8 @@ | |
"@emotion/styled": "^11.6.0", | ||
"@mui/icons-material": "^5.10.15", | ||
"@mui/material": "^5.10.15", | ||
"@okta/okta-auth-js": "^7.7.0", | ||
"@okta/okta-react": "^6.9.0", | ||
"date-fns": "^3.0.6", | ||
"i18next": "^23.0.1", | ||
"react": "^16.13.1 || ^17.0.0 || ^18.0.0", | ||
|