-
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: updated next auth session controller to handle both auth and pr…
…ofile status (#178)
- Loading branch information
Fran McDade
authored and
Fran McDade
committed
Jan 5, 2025
1 parent
d2189df
commit 41a3d58
Showing
6 changed files
with
59 additions
and
170 deletions.
There are no files selected for viewing
8 changes: 6 additions & 2 deletions
8
...ation/components/SessionController/components/NextSessionController/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 |
---|---|---|
@@ -1,19 +1,23 @@ | ||
import { useSession } from "next-auth/react"; | ||
import React, { Fragment, useEffect } from "react"; | ||
import { updateAuthState } from "../../../../../../providers/authentication/auth/dispatch"; | ||
import { useAuth } from "../../../../../../providers/authentication/auth/hook"; | ||
import { updateAuthentication } from "../../../../../../providers/authentication/authentication/dispatch"; | ||
import { useAuthentication } from "../../../../../../providers/authentication/authentication/hook"; | ||
import { SessionControllerProps } from "./types"; | ||
import { mapAuthentication } from "./utils"; | ||
import { mapAuth, mapAuthentication } from "./utils"; | ||
|
||
export function SessionController({ | ||
children, | ||
}: SessionControllerProps): JSX.Element { | ||
const { authDispatch } = useAuth(); | ||
const { authenticationDispatch } = useAuthentication(); | ||
const session = useSession(); | ||
|
||
useEffect(() => { | ||
authDispatch?.(updateAuthState(mapAuth(session))); | ||
authenticationDispatch?.(updateAuthentication(mapAuthentication(session))); | ||
}, [authenticationDispatch, session]); | ||
}, [authDispatch, authenticationDispatch, session]); | ||
|
||
return <Fragment>{children}</Fragment>; | ||
} |
21 changes: 21 additions & 0 deletions
21
...Authentication/components/SessionController/components/NextSessionController/constants.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,21 @@ | ||
import { SessionContextValue } from "next-auth/react"; | ||
import { AUTH_STATUS } from "../../../../../../providers/authentication/auth/types"; | ||
import { AUTHENTICATION_STATUS } from "../../../../../../providers/authentication/authentication/types"; | ||
|
||
export const AUTH_STATUS_MAP: Record< | ||
SessionContextValue["status"], | ||
AUTH_STATUS | ||
> = { | ||
authenticated: AUTH_STATUS.SETTLED, | ||
loading: AUTH_STATUS.PENDING, | ||
unauthenticated: AUTH_STATUS.SETTLED, | ||
}; | ||
|
||
export const AUTHENTICATION_STATUS_MAP: Record< | ||
SessionContextValue["status"], | ||
AUTHENTICATION_STATUS | ||
> = { | ||
authenticated: AUTHENTICATION_STATUS.SETTLED, | ||
loading: AUTHENTICATION_STATUS.PENDING, | ||
unauthenticated: AUTHENTICATION_STATUS.SETTLED, | ||
}; |
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.
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.