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

feat(ui): allow override of resendSignUpCode function call #6312

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions .changeset/great-dogs-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@aws-amplify/ui': minor
---

feat(ui): allow override of resendSignUpCode function call

This feature lets you override the `resendSignUpCode` function call the same way as the `signUp`, `signIn`,
`confirmSignIn`, `confirmSignUp`, `forgotPassword` and `forgotPasswordSubmit` functions.
22 changes: 22 additions & 0 deletions docs/src/components/FunctionOverridesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ export const FunctionOverridesTable = ({ framework }) => {
<code>{'{username, confirmationCode}'}</code>
</ResponsiveTableCell>
</TableRow>
<TableRow>
<ResponsiveTableCell label="Function Call">
<code>resendSignUpCode</code>
</ResponsiveTableCell>
<ResponsiveTableCell label="Override Name">
<code>handleResendSignUpCode</code>
</ResponsiveTableCell>
<ResponsiveTableCell label="input Properties">
<code>{'{username}'}</code>
</ResponsiveTableCell>
</TableRow>
<TableRow>
<ResponsiveTableCell label="Function Call">
<code>resetPassword</code>
Expand Down Expand Up @@ -170,6 +181,17 @@ export const FunctionOverridesTable = ({ framework }) => {
<code>{'{username, code}'}</code>
</ResponsiveTableCell>
</TableRow>
<TableRow>
<ResponsiveTableCell label="Function Call">
<code>Auth.resendSignUpCode</code>
</ResponsiveTableCell>
<ResponsiveTableCell label="Override Name">
<code>handleResendSignUpCode</code>
</ResponsiveTableCell>
<ResponsiveTableCell label="formData Properties">
<code>{'{username}'}</code>
</ResponsiveTableCell>
</TableRow>
<TableRow>
<ResponsiveTableCell label="Function Call">
<code>Auth.forgotPassword</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FunctionOverridesTable } from '@/components/FunctionOverridesTable';

## Override Function Calls

You can override the call to `signUp`, `signIn`, `confirmSignIn`, `confirmSignUp`, `forgotPassword` and `forgotPasswordSubmit` functions.
You can override the call to `signUp`, `signIn`, `confirmSignIn`, `confirmSignUp`, `resendSignUpCode`, `forgotPassword` and `forgotPasswordSubmit` functions.
To override a call you must create a new `services` object with an `async` `handle*` function that returns an `aws-amplify` `Auth` promise.
<ForgotPasswordCallout />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { FunctionOverridesTable } from '@/components/FunctionOverridesTable';

## Override Function Calls

You can override the call to `signUp`, `signIn`, `confirmSignIn`, `confirmSignUp`, `forgotPassword` and `forgotPasswordSubmit` functions.
You can override the call to `signUp`, `signIn`, `confirmSignIn`, `confirmSignUp`, `resendSignUpCode`, `forgotPassword` and `forgotPasswordSubmit` functions.
To override a call you must create a new `services` object with an `async` `handle*` function that returns an `aws-amplify` `Auth` promise.
<ForgotPasswordCallout />
The service object must then be passed into the `authenticator` component as a `services` prop. For example, let's imagine you'd like to lowercase the `username` and the `email` attributes during `signUp`.
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/src/machines/authenticator/actors/signIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
confirmSignIn,
ConfirmSignInInput,
fetchUserAttributes,
resendSignUpCode,
resetPassword,
signInWithRedirect,
} from 'aws-amplify/auth';
Expand Down Expand Up @@ -297,7 +296,7 @@ export function signInActor({ services }: SignInMachineOptions) {
return resetPassword({ username });
},
handleResendSignUpCode({ username }) {
return resendSignUpCode({ username });
return services.handleResendSignUpCode({ username });
},
handleSignIn({ formValues, username }) {
const { password } = formValues;
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/src/machines/authenticator/actors/signUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createMachine, sendUpdate } from 'xstate';
import {
autoSignIn,
ConfirmSignUpInput,
resendSignUpCode,
signInWithRedirect,
fetchUserAttributes,
} from 'aws-amplify/auth';
Expand Down Expand Up @@ -287,7 +286,7 @@ export function signUpActor({ services }: SignUpMachineOptions) {
return services.handleConfirmSignUp(input);
},
resendSignUpCode({ username }) {
return resendSignUpCode({ username });
return services.handleResendSignUpCode({ username });
},
signInWithRedirect(_, { data }) {
return signInWithRedirect(data);
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/machines/authenticator/defaultServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
confirmSignIn,
confirmSignUp,
getCurrentUser,
resendSignUpCode,
resetPassword,
signIn,
signUp,
Expand Down Expand Up @@ -89,6 +90,7 @@ export const defaultServices = {
handleConfirmSignUp: confirmSignUp,
handleForgotPasswordSubmit: confirmResetPassword,
handleForgotPassword: resetPassword,
handleResendSignUpCode: resendSignUpCode,

// Validation hooks for overriding
async validateCustomSignUp(
Expand Down