Skip to content

Commit

Permalink
feat(ui): allow override of resendSignUpCode function call
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin860 committed Jan 27, 2025
1 parent a877c32 commit 59e900a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 6 deletions.
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

0 comments on commit 59e900a

Please sign in to comment.