From 9c834f11093487828251fe61e0f5e4173b1662af Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Tue, 30 Nov 2021 16:23:43 +0100 Subject: [PATCH] Make RedirectLoginOptions and RedirectLoginResult accept generic AppState (#846) * Make RedirectLoginOptions and RedirectLoginResult accept generic AppState * Add TAppState to loginWithRedirect and handleRedirectCallback Co-authored-by: Steve Hobbs --- src/Auth0Client.ts | 8 +++++--- src/global.ts | 9 +++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Auth0Client.ts b/src/Auth0Client.ts index 9d90dfba7..345afef29 100644 --- a/src/Auth0Client.ts +++ b/src/Auth0Client.ts @@ -615,7 +615,9 @@ export default class Auth0Client { * * @param options */ - public async loginWithRedirect(options: RedirectLoginOptions = {}) { + public async loginWithRedirect( + options: RedirectLoginOptions = {} + ) { const { redirectMethod, ...urlOptions } = options; const url = await this.buildAuthorizeUrl(urlOptions); window.location[redirectMethod || 'assign'](url); @@ -627,9 +629,9 @@ export default class Auth0Client { * responses from Auth0. If the response is successful, results * will be valid according to their expiration times. */ - public async handleRedirectCallback( + public async handleRedirectCallback( url: string = window.location.href - ): Promise { + ): Promise> { const queryStringFragments = url.split('?').slice(1); if (queryStringFragments.length === 0) { diff --git a/src/global.ts b/src/global.ts index a85692537..af57fc996 100644 --- a/src/global.ts +++ b/src/global.ts @@ -240,7 +240,8 @@ export interface AuthorizeOptions extends BaseLoginOptions { code_challenge_method: string; } -export interface RedirectLoginOptions extends BaseLoginOptions { +export interface RedirectLoginOptions + extends BaseLoginOptions { /** * The URL where Auth0 will redirect your browser to with * the authentication result. It must be whitelisted in @@ -251,7 +252,7 @@ export interface RedirectLoginOptions extends BaseLoginOptions { /** * Used to store state before doing the redirect */ - appState?: any; + appState?: TAppState; /** * Used to add to the URL fragment before redirecting */ @@ -262,11 +263,11 @@ export interface RedirectLoginOptions extends BaseLoginOptions { redirectMethod?: 'replace' | 'assign'; } -export interface RedirectLoginResult { +export interface RedirectLoginResult { /** * State stored when the redirect request was made */ - appState?: any; + appState?: TAppState; } export interface PopupLoginOptions extends BaseLoginOptions {}