Skip to content

Commit 80ad8cd

Browse files
authored
fix(authenticator): add handling for external sign up events (#5006)
1 parent 983a3c8 commit 80ad8cd

File tree

5 files changed

+80
-13
lines changed

5 files changed

+80
-13
lines changed

Diff for: .changeset/sweet-dodos-thank.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@aws-amplify/ui": patch
3+
---
4+
5+
fix(authenticator): add handling for external sign up events

Diff for: packages/ui/jest.config.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@ import { Config } from 'jest';
22

33
const config: Config = {
44
collectCoverage: true,
5-
collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
6-
coveragePathIgnorePatterns: [
5+
collectCoverageFrom: [
6+
'<rootDir>/src/**/*.ts',
77
// ignore coverage for top level "export"
8-
'<rootDir>/src/index.ts',
8+
'!<rootDir>/src/index.ts',
9+
// ignore internal `debugUtils` from coverage thresholds
10+
'!<rootDir>/**/debugUtils.ts',
911
// ignore coverage for style-dictionary type declaration file
10-
'<rootDir>/src/theme/types/style-dictionary.d.ts',
12+
'!<rootDir>/src/theme/types/style-dictionary.d.ts',
1113
],
1214
coverageThreshold: {
1315
global: {
14-
branches: 77,
15-
functions: 70,
16-
lines: 87,
17-
statements: 88,
16+
branches: 80,
1817
// @todo-migration: put back after fixing tests
19-
// branches: 80,
2018
// functions: 85,
19+
functions: 70,
20+
// @todo-migration: put back after fixing tests
2121
// lines: 90,
22-
// statements: 90,
22+
lines: 87,
23+
statements: 90,
2324
},
2425
},
2526
preset: 'ts-jest',

Diff for: packages/ui/src/helpers/authenticator/debugUtils.ts

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { groupLog } from '../../utils';
2+
import { GetRoute } from './getRoute';
3+
4+
/**
5+
* @internal Not to be used in production
6+
* @description Debugging tool for logging `state` and `actorState`
7+
*
8+
* @example
9+
* ```ts
10+
* const getRouteWithLogs = logRouteChanges(getRoute);
11+
* ```
12+
*/
13+
export const logRouteChanges = (fn: GetRoute): GetRoute => {
14+
let prevStateValue;
15+
let prevActorStateValue;
16+
return (state, actorState) => {
17+
const stateValue = state?.value ? JSON.stringify(state.value) : undefined;
18+
const actorStateValue = actorState?.value
19+
? JSON.stringify(actorState.value)
20+
: undefined;
21+
22+
const bothUpdated =
23+
stateValue !== prevStateValue && actorStateValue !== prevActorStateValue;
24+
25+
const logValues = (label) =>
26+
groupLog(
27+
label,
28+
{ 'state.value': state?.value },
29+
{ 'actorState.value': actorState?.value }
30+
);
31+
32+
if (bothUpdated) {
33+
prevStateValue = stateValue;
34+
prevActorStateValue = actorStateValue;
35+
logValues('state and actorState value updated');
36+
}
37+
38+
if (!bothUpdated && stateValue !== prevStateValue) {
39+
prevStateValue = stateValue;
40+
logValues('state value updated');
41+
}
42+
43+
if (!bothUpdated && actorStateValue !== prevActorStateValue) {
44+
prevActorStateValue = actorStateValue;
45+
logValues('actor state value updated');
46+
}
47+
48+
return fn(state, actorState);
49+
};
50+
};

Diff for: packages/ui/src/helpers/authenticator/getRoute.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ import {
22
AuthActorState,
33
AuthMachineState,
44
} from '../../machines/authenticator/types';
5+
import { AuthenticatorRoute } from './facade';
6+
7+
export type GetRoute = (
8+
state: AuthMachineState,
9+
actorState: AuthActorState
10+
) => AuthenticatorRoute;
511

612
export const getRoute = (
713
state: AuthMachineState,
814
actorState: AuthActorState
9-
) => {
15+
): AuthenticatorRoute => {
1016
// 'federatedSignIn' exists as a state on both the 'signInActor' and 'signUpActor',
1117
// match against the `actorState` initially to determine if the federated sign in flow
1218
// has begun, then which actor has begun the flow and return the corresponding `route`

Diff for: packages/ui/src/machines/authenticator/index.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const stopActor = (machineId: string) => stop(machineId);
5151
const LEGACY_WAIT_CONFIG = {
5252
on: {
5353
INIT: {
54-
actions: ['configure'],
54+
actions: 'configure',
5555
target: 'getConfig',
5656
},
5757
SIGN_OUT: '#authenticator.signOut',
@@ -60,7 +60,7 @@ const LEGACY_WAIT_CONFIG = {
6060

6161
// setup step proceeds directly to configure
6262
const NEXT_WAIT_CONFIG = {
63-
always: { actions: ['configure'], target: 'getConfig' },
63+
always: { actions: 'configure', target: 'getConfig' },
6464
};
6565

6666
export function createAuthenticatorMachine(
@@ -192,6 +192,11 @@ export function createAuthenticatorMachine(
192192
cond: 'hasCompletedAttributeConfirmation',
193193
target: '#authenticator.getCurrentUser',
194194
},
195+
{
196+
cond: 'isShouldConfirmUserAttributeStep',
197+
actions: 'setActorDoneData',
198+
target: '#authenticator.verifyUserAttributesActor',
199+
},
195200
{
196201
cond: 'isConfirmUserAttributeStep',
197202
target: '#authenticator.verifyUserAttributesActor',

0 commit comments

Comments
 (0)