diff --git a/packages/auth-provider/src/common/types.d.ts b/packages/auth-provider/src/common/types.d.ts index a58696d..b6bab2c 100644 --- a/packages/auth-provider/src/common/types.d.ts +++ b/packages/auth-provider/src/common/types.d.ts @@ -5,6 +5,14 @@ import { ACTION_TYPE_LOGOUT, } from "./constants"; +type AuthenticationTypes = + | typeof AUTH_TYPES.PASSKEY + | typeof AUTH_TYPES.CODE + | typeof AUTH_TYPES.ID_TOKEN + | typeof AUTH_TYPES.ACCESS_TOKEN + | typeof AUTH_TYPES.ID_AND_ACCESS_TOKEN + | null; + export type ServiceCallProps = { params: any; clientId: string; @@ -23,6 +31,7 @@ export type AuthState = { isLoading: boolean; isAuthenticated: boolean; logoutReason?: string; + authenticationType: AuthenticationTypes; user?: { userId?: string; username?: string; @@ -54,6 +63,7 @@ export type InternalActions = | { type: typeof ACTION_TYPE_LOGIN; payload: { + authenticationType: AuthenticationTypes; user: { userId: string; username: string; diff --git a/packages/auth-provider/src/components/AuthProvider/AuthContext.ts b/packages/auth-provider/src/components/AuthProvider/AuthContext.ts index e3e022d..3d23d1a 100644 --- a/packages/auth-provider/src/components/AuthProvider/AuthContext.ts +++ b/packages/auth-provider/src/components/AuthProvider/AuthContext.ts @@ -9,6 +9,7 @@ const stub = (): never => { export const AuthContext = createContext({ isAuthenticated: false, isLoading: false, + authenticationType: null, login: stub, logout: stub, getAccessToken: stub, diff --git a/packages/auth-provider/src/components/AuthProvider/AuthProvider.tsx b/packages/auth-provider/src/components/AuthProvider/AuthProvider.tsx index 1e69b1a..bb7337d 100644 --- a/packages/auth-provider/src/components/AuthProvider/AuthProvider.tsx +++ b/packages/auth-provider/src/components/AuthProvider/AuthProvider.tsx @@ -44,6 +44,7 @@ export const AuthProvider = ({ const [state, dispatch] = useReducer(reducer, { isLoading: true, isAuthenticated: false, + authenticationType: null, user: undefined, logoutReason: "", }); @@ -125,6 +126,7 @@ export const AuthProvider = ({ dispatch({ type: ACTION_TYPE_LOGIN, payload: { + authenticationType: jwt.payload[JWT.AUTH_TYPE_KEY] as string, user: { userId: jwt.payload[JWT.USER_ID_KEY] as string, username: jwt.payload[JWT.USERNAME_KEY] as string, @@ -182,6 +184,7 @@ export const AuthProvider = ({ dispatch({ type: ACTION_TYPE_LOGIN, payload: { + authenticationType: type, user: { userId: response.userId as string, username, @@ -212,6 +215,7 @@ export const AuthProvider = ({ dispatch({ type: ACTION_TYPE_LOGIN, payload: { + authenticationType: type as string, user: { userId: response.userId as string, username, @@ -358,6 +362,7 @@ export const AuthProvider = ({ dispatch({ type: ACTION_TYPE_LOGIN, payload: { + authenticationType: AUTH_TYPES.PASSKEY, user: { userId: response.data.userId as string, username: response.data.username as string, diff --git a/packages/auth-provider/src/components/AuthProvider/InternalContext.ts b/packages/auth-provider/src/components/AuthProvider/InternalContext.ts index 899f04e..8adb9ab 100644 --- a/packages/auth-provider/src/components/AuthProvider/InternalContext.ts +++ b/packages/auth-provider/src/components/AuthProvider/InternalContext.ts @@ -8,6 +8,7 @@ export const InternalContext = React.createContext<{ state: { isLoading: true, isAuthenticated: false, + authenticationType: null, user: undefined, logoutReason: "", }, diff --git a/packages/auth-provider/src/components/AuthProvider/reducer.ts b/packages/auth-provider/src/components/AuthProvider/reducer.ts index 96167da..ea9197e 100644 --- a/packages/auth-provider/src/components/AuthProvider/reducer.ts +++ b/packages/auth-provider/src/components/AuthProvider/reducer.ts @@ -19,6 +19,7 @@ export const reducer = (state: AuthState, action: InternalActions) => { isLoading: false, isAuthenticated: true, user: action.payload.user, + authenticationType: action.payload.authenticationType, logoutReason: "", }; } @@ -29,6 +30,7 @@ export const reducer = (state: AuthState, action: InternalActions) => { isLoading: false, isAuthenticated: false, user: undefined, + authenticationType: null, logoutReason: action.payload.logoutReason, }; }