Skip to content

Commit

Permalink
bugfix aws-amplify#5860: using custom state forces congnito UI for cu…
Browse files Browse the repository at this point in the history
…stom provider (aws-amplify#6480)

* bugfix aws-amplify#5860: using custom state forces congnito UI for custom provider

* fix return type and update list of keys to reflect both Options

* Update packages/auth/src/types/Auth.ts

Co-authored-by: Manuel Iglesias <[email protected]>
  • Loading branch information
div5yesh and manueliglesias authored Aug 5, 2020
1 parent 572e746 commit cf25010
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/auth/src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
isCognitoHostedOpts,
isFederatedSignInOptions,
isFederatedSignInOptionsCustom,
hasCustomState,
FederatedSignInOptionsCustom,
LegacyProvider,
FederatedSignInOptions,
Expand Down Expand Up @@ -1787,6 +1788,7 @@ export class AuthClass {
if (
isFederatedSignInOptions(providerOrOptions) ||
isFederatedSignInOptionsCustom(providerOrOptions) ||
hasCustomState(providerOrOptions) ||
typeof providerOrOptions === 'undefined'
) {
const options = providerOrOptions || {
Expand Down
15 changes: 10 additions & 5 deletions packages/auth/src/types/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,22 @@ export type FederatedSignInOptionsCustom = {
export function isFederatedSignInOptions(
obj: any
): obj is FederatedSignInOptions {
const keys: (keyof FederatedSignInOptions)[] = ['provider', 'customState'];
const keys: (keyof FederatedSignInOptions)[] = ['provider'];
return obj && !!keys.find(k => obj.hasOwnProperty(k));
}

export function isFederatedSignInOptionsCustom(
obj: any
): obj is FederatedSignInOptionsCustom {
const keys: (keyof FederatedSignInOptionsCustom)[] = [
'customProvider',
'customState',
];
const keys: (keyof FederatedSignInOptionsCustom)[] = ['customProvider'];
return obj && !!keys.find(k => obj.hasOwnProperty(k));
}

export function hasCustomState(obj: any): boolean {
const keys: (keyof (
| FederatedSignInOptions
| FederatedSignInOptionsCustom
))[] = ['customState'];
return obj && !!keys.find(k => obj.hasOwnProperty(k));
}

Expand Down

0 comments on commit cf25010

Please sign in to comment.