Skip to content

Commit

Permalink
add config argument to loginWithPopup (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aulos committed Aug 4, 2020
1 parent 387b3d4 commit caa2d09
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/auth0-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IdToken,
LogoutOptions,
PopupLoginOptions,
PopupConfigOptions,
} from '@auth0/auth0-spa-js';
import { createContext } from 'react';
import { AuthState, initialAuthState } from './auth-state';
Expand Down Expand Up @@ -100,7 +101,7 @@ export interface Auth0ContextInterface extends AuthState {

/**
* ```js
* await loginWithPopup(options);
* await loginWithPopup(options, config);
* ```
*
* Opens a popup with the `/authorize` URL using the parameters
Expand All @@ -112,7 +113,10 @@ export interface Auth0ContextInterface extends AuthState {
* that was started by the user like a button click, for example,
* otherwise the popup will be blocked in most browsers.
*/
loginWithPopup: (options?: PopupLoginOptions) => Promise<void>;
loginWithPopup: (
options?: PopupLoginOptions,
config?: PopupConfigOptions
) => Promise<void>;

/**
* ```js
Expand Down
10 changes: 7 additions & 3 deletions src/auth0-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
CacheLocation,
IdToken,
PopupLoginOptions,
PopupConfigOptions,
RedirectLoginOptions as Auth0RedirectLoginOptions,
} from '@auth0/auth0-spa-js';
import Auth0Context, { RedirectLoginOptions } from './auth0-context';
Expand Down Expand Up @@ -207,10 +208,13 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
})();
}, [client, onRedirectCallback]);

const loginWithPopup = async (options?: PopupLoginOptions): Promise<void> => {
const loginWithPopup = async (
options?: PopupLoginOptions,
config?: PopupConfigOptions
): Promise<void> => {
dispatch({ type: 'LOGIN_POPUP_STARTED' });
try {
await client.loginWithPopup(options);
await client.loginWithPopup(options, config);
} catch (error) {
dispatch({ type: 'ERROR', error: loginError(error) });
return;
Expand All @@ -234,7 +238,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
client.getIdTokenClaims(opts),
loginWithRedirect: (opts): Promise<void> =>
client.loginWithRedirect(toAuth0LoginRedirectOptions(opts)),
loginWithPopup: (opts): Promise<void> => loginWithPopup(opts),
loginWithPopup,
logout: (opts): void => client.logout(opts),
}}
>
Expand Down

0 comments on commit caa2d09

Please sign in to comment.