Skip to content

Commit

Permalink
expose signinCallback for native applications
Browse files Browse the repository at this point in the history
  • Loading branch information
Timo Jancke committed Aug 11, 2024
1 parent 2d31f2d commit 4fadc00
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/react-oidc-context.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const AuthContext: React_2.Context<AuthContextProps | undefined>;

// @public (undocumented)
export interface AuthContextProps extends AuthState {
// (undocumented)
callSigninCallback(url: string): Promise<void>;
// (undocumented)
clearStaleState(): Promise<void>;
// (undocumented)
Expand Down
1 change: 1 addition & 0 deletions src/AuthContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface AuthContextProps extends AuthState {
revokeTokens(types?: RevokeTokensTypes): Promise<void>;
startSilentRenew(): void;
stopSilentRenew(): void;
callSigninCallback(url: string): Promise<void>;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,21 @@ export const AuthProvider = (props: AuthProviderProps): JSX.Element => {
onRemoveUser && await onRemoveUser();
}, [userManager, onRemoveUser]);

const callSigninCallback = async (url: string) => {
let user: User | void | null = null;
user = await userManager.signinCallback(url);
onSigninCallback && await onSigninCallback(user);
user = !user ? await userManager.getUser() : user;
dispatch({ type: "INITIALISED", user });
};

return (
<AuthContext.Provider
value={{
...state,
...userManagerContext,
removeUser,
callSigninCallback,
}}
>
{children}
Expand Down

0 comments on commit 4fadc00

Please sign in to comment.