Skip to content

Commit

Permalink
Make RedirectLoginOptions and RedirectLoginResult accept generic AppS…
Browse files Browse the repository at this point in the history
…tate (#846)

* Make RedirectLoginOptions and RedirectLoginResult accept generic AppState

* Add TAppState to loginWithRedirect and handleRedirectCallback

Co-authored-by: Steve Hobbs <[email protected]>
  • Loading branch information
frederikprijck and Steve Hobbs authored Nov 30, 2021
1 parent b1d26e7 commit 9c834f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/Auth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,9 @@ export default class Auth0Client {
*
* @param options
*/
public async loginWithRedirect(options: RedirectLoginOptions = {}) {
public async loginWithRedirect<TAppState = any>(
options: RedirectLoginOptions<TAppState> = {}
) {
const { redirectMethod, ...urlOptions } = options;
const url = await this.buildAuthorizeUrl(urlOptions);
window.location[redirectMethod || 'assign'](url);
Expand All @@ -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<TAppState = any>(
url: string = window.location.href
): Promise<RedirectLoginResult> {
): Promise<RedirectLoginResult<TAppState>> {
const queryStringFragments = url.split('?').slice(1);

if (queryStringFragments.length === 0) {
Expand Down
9 changes: 5 additions & 4 deletions src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ export interface AuthorizeOptions extends BaseLoginOptions {
code_challenge_method: string;
}

export interface RedirectLoginOptions extends BaseLoginOptions {
export interface RedirectLoginOptions<TAppState = any>
extends BaseLoginOptions {
/**
* The URL where Auth0 will redirect your browser to with
* the authentication result. It must be whitelisted in
Expand All @@ -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
*/
Expand All @@ -262,11 +263,11 @@ export interface RedirectLoginOptions extends BaseLoginOptions {
redirectMethod?: 'replace' | 'assign';
}

export interface RedirectLoginResult {
export interface RedirectLoginResult<TAppState = any> {
/**
* State stored when the redirect request was made
*/
appState?: any;
appState?: TAppState;
}

export interface PopupLoginOptions extends BaseLoginOptions {}
Expand Down

0 comments on commit 9c834f1

Please sign in to comment.