Skip to content

Commit

Permalink
Add revoke function to top level hook
Browse files Browse the repository at this point in the history
  • Loading branch information
mnemitz committed Dec 18, 2024
1 parent 7eef865 commit a6d4614
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/hooks/auth0-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
PasswordlessWithSMSOptions,
ClearSessionOptions,
ExchangeNativeSocialOptions,
RevokeOptions,
} from '../types';

export interface Auth0ContextInterface<TUser extends User = User>
Expand Down Expand Up @@ -113,6 +114,10 @@ export interface Auth0ContextInterface<TUser extends User = User>
* Clears the user's credentials without clearing their web session and logs them out.
*/
clearCredentials: () => Promise<void>;
/**
*Revokes an issued refresh token. See {@link Auth#revoke}
*/
revoke: (parameters: RevokeOptions) => Promise<void>;
}

export interface AuthState<TUser extends User = User> {
Expand Down Expand Up @@ -152,6 +157,7 @@ const initialContext = {
clearSession: stub,
getCredentials: stub,
clearCredentials: stub,
revoke: stub,
};

const Auth0Context = createContext<Auth0ContextInterface>(initialContext);
Expand Down
45 changes: 45 additions & 0 deletions src/hooks/auth0-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
MultifactorChallengeOptions,
PasswordlessWithEmailOptions,
PasswordlessWithSMSOptions,
RevokeOptions,
User,
WebAuthorizeOptions,
WebAuthorizeParameters,
Expand Down Expand Up @@ -336,6 +337,40 @@ const Auth0Provider = ({
}
}, [client]);

<<<<<<< HEAD
=======
const requireLocalAuthentication = useCallback(
async (
title?: string,
description?: string,
cancelTitle?: string,
fallbackTitle?: string,
strategy = LocalAuthenticationStrategy.deviceOwnerWithBiometrics
) => {
try {
await client.credentialsManager.requireLocalAuthentication(
title,
description,
cancelTitle,
fallbackTitle,
strategy
);
} catch (error) {
dispatch({ type: 'ERROR', error });
return;
}
},
[client.credentialsManager]
);

const revoke = useCallback(
(parameters: RevokeOptions) => {
return client.auth.revoke(parameters);
},
[client]
);

>>>>>>> b6515de (Add revoke function to top level hook)
const contextValue = useMemo(
() => ({
...state,
Expand All @@ -353,6 +388,11 @@ const Auth0Provider = ({
clearSession,
getCredentials,
clearCredentials,
<<<<<<< HEAD
=======
requireLocalAuthentication,
revoke,
>>>>>>> b6515de (Add revoke function to top level hook)
}),
[
state,
Expand All @@ -370,6 +410,11 @@ const Auth0Provider = ({
clearSession,
getCredentials,
clearCredentials,
<<<<<<< HEAD
=======
requireLocalAuthentication,
revoke,
>>>>>>> b6515de (Add revoke function to top level hook)
]
);

Expand Down

0 comments on commit a6d4614

Please sign in to comment.