Skip to content

Commit

Permalink
Merge pull request #1377 from authts/feat-on-signout-callback
Browse files Browse the repository at this point in the history
pass signoutCallback reponse to onSignoutCallback
  • Loading branch information
pamapa authored Oct 4, 2024
2 parents 3345125 + 8053b38 commit 3c9a387
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/react-oidc-context.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { SigninResourceOwnerCredentialsArgs } from 'oidc-client-ts';
import type { SigninSilentArgs } from 'oidc-client-ts';
import type { SignoutPopupArgs } from 'oidc-client-ts';
import type { SignoutRedirectArgs } from 'oidc-client-ts';
import type { SignoutResponse } from 'oidc-client-ts';
import type { SignoutSilentArgs } from 'oidc-client-ts';
import { User } from 'oidc-client-ts';
import { UserManager } from 'oidc-client-ts';
Expand Down Expand Up @@ -65,7 +66,7 @@ export interface AuthProviderBaseProps {
matchSignoutCallback?: (args: UserManagerSettings) => boolean;
onRemoveUser?: () => Promise<void> | void;
onSigninCallback?: (user: User | undefined) => Promise<void> | void;
onSignoutCallback?: () => Promise<void> | void;
onSignoutCallback?: (resp: SignoutResponse | undefined) => Promise<void> | void;
skipSigninCallback?: boolean;
}

Expand Down
9 changes: 5 additions & 4 deletions src/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { UserManager, type UserManagerSettings, User } from "oidc-client-ts";
import type {
ProcessResourceOwnerPasswordCredentialsArgs,
SignoutResponse,
} from "oidc-client-ts";

import { AuthContext } from "./AuthContext";
Expand Down Expand Up @@ -71,13 +72,13 @@ export interface AuthProviderBaseProps {
* When using this, specifying `matchSignoutCallback` is required.
*
* ```jsx
* const onSignoutCallback = (): void => {
* const onSignoutCallback = (resp: SignoutResponse | undefined): void => {
* // go to home after logout
* window.location.pathname = ""
* }
* ```
*/
onSignoutCallback?: () => Promise<void> | void;
onSignoutCallback?: (resp: SignoutResponse | undefined) => Promise<void> | void;

/**
* On remove user hook. Can be a async function.
Expand Down Expand Up @@ -240,8 +241,8 @@ export const AuthProvider = (props: AuthProviderProps): JSX.Element => {
// sign-out
try {
if (matchSignoutCallback && matchSignoutCallback(userManager.settings)) {
await userManager.signoutCallback();
onSignoutCallback && (await onSignoutCallback());
const resp = await userManager.signoutCallback();
onSignoutCallback && await onSignoutCallback(resp);
}
} catch (error) {
dispatch({ type: "ERROR", error: signoutError(error) });
Expand Down

0 comments on commit 3c9a387

Please sign in to comment.