Commit 1390ec7
authored
feat(auth): migrate auth APIs to AmplifyContext (#14836)
* feat(auth): migrate auth APIs to AmplifyContext (B-auth split)
- Add AmplifyContext overloads to all public auth APIs (signIn, signUp,
signOut, getCurrentUser, fetchUserAttributes, confirmSignIn, etc.)
- Public APIs use resolveCtxArgs with getGlobalContext() fallback
- Server wrappers (server/getCurrentUser, server/fetchUserAttributes)
take AmplifyContext explicitly — no global fallback
- Internal signIn variants take (ctx, input) directly
- Utilities (assertUserNotAuthenticated, dispatchSignedInHubEvent) accept ctx
- Replace Amplify.getConfig() with ctx.resourcesConfig throughout
- Replace AmplifyClassV6 with AmplifyContext in internal APIs
- Add createMockAmplifyContext test utility
- Update affected test files to use mock context
* fix: use resolveCtxArgs<[]> for no-input overloads
resolveCtxArgs generic constraint requires T extends unknown[].
undefined does not satisfy this - use empty tuple [] instead.
* fix: use ctx.fetchAuthSession() instead of singleton fetchAuthSession()
The fetchAuthSession helper from core/internals/utils expects AmplifyClass,
not AmplifyContext. Use the context's own fetchAuthSession method directly.
* fix: server wrappers accept both AmplifyContext and ContextSpec
Maintain backward compatibility with adapter-nextjs which still uses
runWithAmplifyServerContext + ContextSpec pattern. Server wrappers now
detect whether they received an AmplifyContext or ContextSpec and
resolve accordingly.
* fix: resolve lint and formatting issues
- Remove unused Amplify imports from test files
- Fix prettier formatting (line length, indentation)
* fix: remove tsconfig.tsbuildinfo build artifact
* fix: update auth tests to use AmplifyContext directly
Migrate test mocking from Amplify.getConfig() singleton to passing
mockCtx directly via createMockAmplifyContext(). This aligns tests
with the new resolveCtxArgs pattern where APIs accept an optional
AmplifyContext as their first argument.
- Remove jest.mock('@aws-amplify/core') in favor of direct ctx passing
- Replace fetchAuthSession singleton mock with ctx.fetchAuthSession
- Use customCtx for endpoint override tests
- Fix autoSignInUserConfirmed to match updated signUpHelpers routing
- Add Amplify.configure() for tests that reach getSignInResult (still
uses singleton internally)
* fix(auth): address PR review comments
- Restore USER_AUTH branch in signUpHelpers auto-sign-in: route directly
to signInWithUserAuth(getGlobalContext(), input) instead of signIn(),
which called resetAutoSignIn() and dropped the primed autoSignInStore
session (regression). Re-add the dropped session assertion in
autoSignIn.test.ts and correct autoSignInUserConfirmed.test.ts to
assert the restored behavior.
- Extract duplicated server context resolution into resolveServerContext
shared util, used by server/getCurrentUser and server/fetchUserAttributes.
- Add clearGlobalContext() cleanup in afterAll across test files that set
a global context; make the Cognito ASF suite self-contained instead of
relying on cross-describe context leakage.
* fix(auth): correct import order in autoSignInUserConfirmed test
Move @aws-amplify/core/internals/utils import before relative src imports
to satisfy eslint import/order.
* test(rtn-passkeys): use iPhone 17 simulator for iOS unit tests
macos-latest runner's Xcode no longer ships the iPhone 16 simulator by
default; target iPhone 17 so the xcodebuild test destination resolves.
* fix(auth): address review feedback on context threading
- Thread ctx:AmplifyContext through getSignInResult and
handleWebAuthnSignInResult (incl. WEB_AUTHN recursion) so the
MFA_SETUP/TOTP associateSoftwareToken call uses the same context as
the rest of the sign-in flow instead of the global singleton config.
Updated all 6 callers to pass ctx.
- signOut: use ctx.clearCredentials() instead of the singleton in the
non-OAuth branch so per-request credential state is cleared.
- signUpHelpers: pass getGlobalContext() explicitly in the non-USER_AUTH
auto-sign-in branch for symmetry with the USER_AUTH branch.
- Add focused unit test for resolveServerContext covering both the
AmplifyContext and legacy ContextSpec branches.
- Collapse verbose comment in resolveServerContext to one line.1 parent 5b0f745 commit 1390ec7
78 files changed
Lines changed: 1216 additions & 794 deletions
File tree
- packages
- auth
- __tests__
- providers/cognito
- apis/server
- utils
- oauth
- signInHelpers
- signUpHelpers
- testUtils
- src
- client/flows/userAuth
- providers/cognito
- apis
- internal
- server
- utils
- oauth
- rtn-passkeys
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
Lines changed: 9 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
5 | 6 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
| 7 | + | |
11 | 8 | | |
12 | 9 | | |
13 | 10 | | |
| |||
45 | 42 | | |
46 | 43 | | |
47 | 44 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 45 | + | |
| 46 | + | |
52 | 47 | | |
53 | 48 | | |
54 | 49 | | |
| |||
73 | 68 | | |
74 | 69 | | |
75 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
76 | 75 | | |
77 | 76 | | |
78 | 77 | | |
| |||
Lines changed: 28 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | 4 | | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
10 | 8 | | |
11 | 9 | | |
| 10 | + | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 14 | + | |
25 | 15 | | |
26 | 16 | | |
27 | 17 | | |
28 | 18 | | |
29 | 19 | | |
30 | 20 | | |
31 | | - | |
32 | 21 | | |
33 | 22 | | |
34 | 23 | | |
| |||
37 | 26 | | |
38 | 27 | | |
39 | 28 | | |
40 | | - | |
41 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
42 | 37 | | |
43 | 38 | | |
44 | 39 | | |
| |||
58 | 53 | | |
59 | 54 | | |
60 | 55 | | |
61 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
62 | 60 | | |
63 | 61 | | |
64 | 62 | | |
65 | 63 | | |
66 | 64 | | |
67 | 65 | | |
68 | | - | |
| 66 | + | |
69 | 67 | | |
70 | 68 | | |
71 | 69 | | |
| |||
76 | 74 | | |
77 | 75 | | |
78 | 76 | | |
79 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | | - | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| |||
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
110 | | - | |
| 111 | + | |
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
| |||
123 | 124 | | |
124 | 125 | | |
125 | 126 | | |
126 | | - | |
| 127 | + | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| |||
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
142 | | - | |
| 143 | + | |
143 | 144 | | |
144 | 145 | | |
145 | 146 | | |
| |||
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
163 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
164 | 168 | | |
165 | 169 | | |
166 | 170 | | |
| |||
176 | 180 | | |
177 | 181 | | |
178 | 182 | | |
179 | | - | |
| 183 | + | |
180 | 184 | | |
181 | 185 | | |
182 | 186 | | |
| |||
Lines changed: 15 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | 1 | | |
4 | 2 | | |
5 | 3 | | |
6 | 4 | | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
| 8 | + | |
10 | 9 | | |
11 | 10 | | |
12 | | - | |
13 | 11 | | |
14 | 12 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | 13 | | |
20 | 14 | | |
21 | 15 | | |
22 | 16 | | |
23 | 17 | | |
24 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
25 | 29 | | |
26 | 30 | | |
27 | 31 | | |
| |||
34 | 38 | | |
35 | 39 | | |
36 | 40 | | |
37 | | - | |
38 | 41 | | |
39 | 42 | | |
40 | 43 | | |
| |||
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
59 | | - | |
| 62 | + | |
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
| |||
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
69 | | - | |
| 72 | + | |
70 | 73 | | |
71 | 74 | | |
72 | 75 | | |
| |||
81 | 84 | | |
82 | 85 | | |
83 | 86 | | |
84 | | - | |
| 87 | + | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
| |||
99 | 102 | | |
100 | 103 | | |
101 | 104 | | |
102 | | - | |
| 105 | + | |
103 | 106 | | |
104 | 107 | | |
105 | 108 | | |
| |||
0 commit comments