Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RedirectLoginOptions and RedirectLoginResult accept generic AppState #846

Merged
merged 3 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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