Skip to content

Commit

Permalink
fix: pass response to onSignoutCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
pamapa committed Oct 4, 2024
1 parent b74c7e8 commit 98cb713
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 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 @@ -76,7 +77,7 @@ export interface AuthProviderPropsBase extends UserManagerSettings {
matchSignoutCallback?: (args: UserManagerSettings) => boolean;
onRemoveUser?: () => Promise<void> | void;
onSigninCallback?: (user: User | void) => Promise<void> | void;
onSignoutCallback?: () => Promise<void> | void;
onSignoutCallback?: (resp: SignoutResponse | void) => Promise<void> | void;
// @deprecated (undocumented)
onSignoutPopup?: () => Promise<void> | void;
// @deprecated (undocumented)
Expand Down
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"prepare": "husky install"
},
"peerDependencies": {
"oidc-client-ts": "^2.2.1",
"oidc-client-ts": "^2.4.1",
"react": ">=16.8.0"
},
"devDependencies": {
Expand Down
9 changes: 5 additions & 4 deletions src/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
SignoutPopupArgs,
SignoutSilentArgs,
ProcessResourceOwnerPasswordCredentialsArgs,
SignoutResponse,
} from "oidc-client-ts";

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

/**
* On remove user hook. Can be a async function.
Expand Down Expand Up @@ -256,8 +257,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 98cb713

Please sign in to comment.