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

fix(rna): replace useAuthenticator signOut with default version #4942

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/nice-pens-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aws-amplify/ui-react-native": patch
---

fix(rna): replace useAuthenticator signOut with default version
4 changes: 1 addition & 3 deletions packages/react-native/src/Authenticator/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export { default as Authenticator } from './Authenticator';
export { AuthenticatorProps, WithAuthenticatorOptions } from './types';
export { useAuthenticator, UseAuthenticator } from './useAuthenticator';
export { default as withAuthenticator } from './withAuthenticator';

// re-export shared `Authenticator` exports
export { useAuthenticator, UseAuthenticator } from '@aws-amplify/ui-react-core';
34 changes: 34 additions & 0 deletions packages/react-native/src/Authenticator/useAuthenticator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// re-export `UseAuthenticator` export
export { UseAuthenticator } from '@aws-amplify/ui-react-core';

import { signOut as _signOut } from 'aws-amplify/auth';
import { AuthEventData } from '@aws-amplify/ui';

import {
useAuthenticator as _useAuthenticator,
UseAuthenticator,
} from '@aws-amplify/ui-react-core';

// wrap and re-export `useAuthenticator` to replace state machine `signOut` with
// `aws-amplify/auth` version due to iOS specifc requirements for federated sign
// out handling with JS. On iOS sign out, JS prmnpts the end user with a native
// Alert requesting confirmation of sign out, if the end user cancels they will
// have already been signed out of the state machine, but will still be
// authenticated on the JS singleton

// input utility function to prevent breaking changes in consumers.
// State machine sign out handling does not pass input to underlying `signOut`
// call; replicate that behavior here
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const signOut = (data?: AuthEventData) => {
_signOut();
};

// selector utility type to prevent breaking type changes in consumers
type UseAuthenticatorSelector = Parameters<typeof _useAuthenticator>[0];

export function useAuthenticator(
selector?: UseAuthenticatorSelector
): UseAuthenticator {
return { ..._useAuthenticator(selector), signOut };
}
Loading