-
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.
feat: added session controller to google sign in for non-terra relate…
…d authentication (#178)
- Loading branch information
Fran McDade
authored and
Fran McDade
committed
Jan 5, 2025
1 parent
a383043
commit 05fa1ed
Showing
16 changed files
with
180 additions
and
30 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...ion/components/SessionController/components/GoogleSessionController/SessionController.tsx
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,38 @@ | ||
import React, { Fragment, useEffect } from "react"; | ||
import { authComplete } from "../../../../../../providers/authentication/auth/dispatch"; | ||
import { useAuth } from "../../../../../../providers/authentication/auth/hook"; | ||
import { authenticationComplete } from "../../../../../../providers/authentication/authentication/dispatch"; | ||
import { useAuthentication } from "../../../../../../providers/authentication/authentication/hook"; | ||
import { updateCredentials } from "../../../../../../providers/authentication/credentials/dispatch"; | ||
import { useCredentials } from "../../../../../../providers/authentication/credentials/hook"; | ||
import { SessionControllerProps } from "./types"; | ||
|
||
export function SessionController({ | ||
children, | ||
token, | ||
}: SessionControllerProps): JSX.Element { | ||
const { authDispatch } = useAuth(); | ||
const { | ||
authenticationDispatch, | ||
authenticationState: { profile }, | ||
} = useAuthentication(); | ||
const { credentialsDispatch } = useCredentials(); | ||
|
||
useEffect(() => { | ||
// Dispatch only when profile is available: | ||
// - Login errors are managed by the login service. | ||
// - Logout operations handle resetting credentials and authentication state. | ||
if (!profile) return; | ||
credentialsDispatch?.(updateCredentials(token)); // Release credentials. | ||
authenticationDispatch?.(authenticationComplete()); // Authentication `status` is "SETTLED". | ||
authDispatch?.(authComplete({ isAuthenticated: true })); // Auth `status` is "SETTLED", and `isAuthenticated` is "true". | ||
}, [ | ||
authDispatch, | ||
authenticationDispatch, | ||
credentialsDispatch, | ||
profile, | ||
token, | ||
]); | ||
|
||
return <Fragment>{children}</Fragment>; | ||
} |
7 changes: 7 additions & 0 deletions
7
...s/Authentication/components/SessionController/components/GoogleSessionController/types.ts
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,7 @@ | ||
import { ReactNode } from "react"; | ||
import { TokenState } from "../../../../../../providers/authentication/token/types"; | ||
|
||
export interface SessionControllerProps { | ||
children: ReactNode | ReactNode[]; | ||
token: TokenState["token"]; | ||
} |
4 changes: 2 additions & 2 deletions
4
...s/SessionController/SessionController.tsx → ...xtSessionController/SessionController.tsx
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
File renamed without changes.
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 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,7 +1,7 @@ | ||
import { ElementType, ReactNode } from "react"; | ||
|
||
export interface GoogleSignInAuthenticationProviderProps { | ||
APIServicesProvider: ElementType; | ||
children: ReactNode | ReactNode[]; | ||
SessionController?: ElementType; | ||
timeout?: number; | ||
} |
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.