From a6d46141f06641fae7d923f8b08e6f0acc41d27f Mon Sep 17 00:00:00 2001 From: Matt Nemitz Date: Fri, 20 Sep 2024 10:31:02 +0100 Subject: [PATCH] Add revoke function to top level hook --- src/hooks/auth0-context.ts | 6 +++++ src/hooks/auth0-provider.tsx | 45 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/hooks/auth0-context.ts b/src/hooks/auth0-context.ts index d1babd44..75e044cd 100644 --- a/src/hooks/auth0-context.ts +++ b/src/hooks/auth0-context.ts @@ -15,6 +15,7 @@ import { PasswordlessWithSMSOptions, ClearSessionOptions, ExchangeNativeSocialOptions, + RevokeOptions, } from '../types'; export interface Auth0ContextInterface @@ -113,6 +114,10 @@ export interface Auth0ContextInterface * Clears the user's credentials without clearing their web session and logs them out. */ clearCredentials: () => Promise; + /** + *Revokes an issued refresh token. See {@link Auth#revoke} + */ + revoke: (parameters: RevokeOptions) => Promise; } export interface AuthState { @@ -152,6 +157,7 @@ const initialContext = { clearSession: stub, getCredentials: stub, clearCredentials: stub, + revoke: stub, }; const Auth0Context = createContext(initialContext); diff --git a/src/hooks/auth0-provider.tsx b/src/hooks/auth0-provider.tsx index 58646235..8dc10a55 100644 --- a/src/hooks/auth0-provider.tsx +++ b/src/hooks/auth0-provider.tsx @@ -23,6 +23,7 @@ import { MultifactorChallengeOptions, PasswordlessWithEmailOptions, PasswordlessWithSMSOptions, + RevokeOptions, User, WebAuthorizeOptions, WebAuthorizeParameters, @@ -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, @@ -353,6 +388,11 @@ const Auth0Provider = ({ clearSession, getCredentials, clearCredentials, +<<<<<<< HEAD +======= + requireLocalAuthentication, + revoke, +>>>>>>> b6515de (Add revoke function to top level hook) }), [ state, @@ -370,6 +410,11 @@ const Auth0Provider = ({ clearSession, getCredentials, clearCredentials, +<<<<<<< HEAD +======= + requireLocalAuthentication, + revoke, +>>>>>>> b6515de (Add revoke function to top level hook) ] );