Skip to content

Commit 8a12ee6

Browse files
authored
Bump aws-amplify version (#14706)
Fixes #14704 Migrated to amplify v6. Needed some patches, as the new version does not envision external browser and deeplinks redirects. # Important Notes Requires QA of various ways of logging in and using 2FA
1 parent 9a8d94a commit 8a12ee6

File tree

12 files changed

+1740
-950
lines changed

12 files changed

+1740
-950
lines changed

MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ register_toolchains("//toolchains:windows_builtin_tar_toolchain")
4646
npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
4747
npm.npm_translate_lock(
4848
name = "npm",
49+
data = [
50+
"//:patches/@aws-amplify__auth.patch",
51+
],
4952
npmrc = "//:.npmrc",
5053
pnpm_lock = "//:pnpm-lock.yaml",
5154
verify_node_modules_ignored = "//:.bazelignore",

app/gui/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
"@ag-grid-community/styles": "^32.3.3",
4747
"@ag-grid-enterprise/core": "^32.3.3",
4848
"@ag-grid-enterprise/range-selection": "^32.3.3",
49-
"@aws-amplify/auth": "5.6.5",
50-
"@aws-amplify/core": "5.8.5",
49+
"aws-amplify": "^6.16.0",
5150
"@babel/parser": "^7.26.3",
5251
"@codemirror/autocomplete": "catalog:",
5352
"@codemirror/commands": "^6.8.1",
@@ -150,7 +149,7 @@
150149
"@types/mapbox-gl": "^3.4.1",
151150
"@types/node": "catalog:",
152151
"@types/papaparse": "^5.3.15",
153-
"@types/react": "^18.3.18",
152+
"@types/react": "^18.3.1",
154153
"@types/react-dom": "^18.3.5",
155154
"@types/shuffle-seed": "^1.1.3",
156155
"@types/tar": "^6.1.13",
@@ -204,7 +203,6 @@
204203
"zip-stream": "^7.0.2"
205204
},
206205
"overrides": {
207-
"@aws-amplify/auth": "../_IGNORED_",
208206
"react-native-url-polyfill": "../_IGNORED_"
209207
}
210208
}

app/gui/src/authentication/cognito.mock.ts

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
* `kind` field provides a unique string that can be used to brand the error in place of the
3232
* `internalCode`, when rethrowing the error.
3333
*/
34-
import type * as amplify from '@aws-amplify/auth'
3534
import type * as cognito from 'amazon-cognito-identity-js'
3635
import * as results from 'ts-results'
3736

@@ -185,7 +184,8 @@ export class Cognito {
185184
*/
186185
async signInWithApple() {
187186
this.isSignedIn = true
188-
listen.authEventListener?.(listen.AuthEvent.signIn)
187+
listen.authEventListener?.(listen.AuthEvent.signInWithRedirect)
188+
listen.authEventListener?.(listen.AuthEvent.signedIn)
189189
await Promise.resolve()
190190
}
191191

@@ -198,7 +198,8 @@ export class Cognito {
198198
*/
199199
async signInWithMicrosoft() {
200200
this.isSignedIn = true
201-
listen.authEventListener?.(listen.AuthEvent.signIn)
201+
listen.authEventListener?.(listen.AuthEvent.signInWithRedirect)
202+
listen.authEventListener?.(listen.AuthEvent.signedIn)
202203
await Promise.resolve()
203204
}
204205

@@ -211,7 +212,8 @@ export class Cognito {
211212
*/
212213
async signInWithGoogle() {
213214
this.isSignedIn = true
214-
listen.authEventListener?.(listen.AuthEvent.signIn)
215+
listen.authEventListener?.(listen.AuthEvent.signInWithRedirect)
216+
listen.authEventListener?.(listen.AuthEvent.signedIn)
215217
await Promise.resolve()
216218
}
217219

@@ -224,7 +226,8 @@ export class Cognito {
224226
*/
225227
signInWithGitHub() {
226228
this.isSignedIn = true
227-
listen.authEventListener?.(listen.AuthEvent.signIn)
229+
listen.authEventListener?.(listen.AuthEvent.signInWithRedirect)
230+
listen.authEventListener?.(listen.AuthEvent.signedIn)
228231
return Promise.resolve({
229232
accessKeyId: 'access key id',
230233
sessionToken: 'session token',
@@ -245,7 +248,7 @@ export class Cognito {
245248
mockEmail = username
246249
localStorage.setItem(MOCK_EMAIL_KEY, username)
247250
const result = await results.Result.wrapAsync(async () => {
248-
listen.authEventListener?.(listen.AuthEvent.signIn)
251+
listen.authEventListener?.(listen.AuthEvent.signedIn)
249252
return Promise.resolve(await this.userSession())
250253
})
251254
return result
@@ -256,7 +259,7 @@ export class Cognito {
256259
/** Sign out the current user. */
257260
async signOut() {
258261
this.isSignedIn = false
259-
listen.authEventListener?.(listen.AuthEvent.signOut)
262+
listen.authEventListener?.(listen.AuthEvent.signedOut)
260263
localStorage.removeItem(MOCK_EMAIL_KEY)
261264
localStorage.removeItem(MOCK_ORGANIZATION_ID_KEY)
262265
return Promise.resolve(null)
@@ -301,18 +304,13 @@ export class Cognito {
301304
* component.
302305
*/
303306
async changePassword(oldPassword: string, newPassword: string) {
304-
const cognitoUserResult = await currentAuthenticatedUser()
305-
if (cognitoUserResult.ok) {
306-
const result = await results.Result.wrapAsync(() =>
307-
fetch('https://mock-cognito.com/change-password', {
308-
method: 'POST',
309-
body: JSON.stringify({ oldPassword, newPassword }),
310-
}),
311-
)
312-
return result.mapErr(original.intoAmplifyErrorOrThrow)
313-
} else {
314-
return results.Err(cognitoUserResult.val)
315-
}
307+
const result = await results.Result.wrapAsync(() =>
308+
fetch('https://mock-cognito.com/change-password', {
309+
method: 'POST',
310+
body: JSON.stringify({ oldPassword, newPassword }),
311+
}),
312+
)
313+
return result.mapErr(original.intoAmplifyErrorOrThrow)
316314
}
317315

318316
/** Refresh the current user's session. */
@@ -387,15 +385,3 @@ async function confirmSignUp(_email: string, _code: string) {
387385
result.mapErr(original.intoAmplifyErrorOrThrow).mapErr(original.intoConfirmSignUpErrorOrThrow),
388386
)
389387
}
390-
391-
/**
392-
* A wrapper around the Amplify "current authenticated user" endpoint that converts known errors
393-
* to `AmplifyError`s.
394-
*/
395-
async function currentAuthenticatedUser() {
396-
const result = await results.Result.wrapAsync(
397-
// The methods are not needed.
398-
async () => await Promise.resolve<amplify.CognitoUser>({} as unknown as amplify.CognitoUser),
399-
)
400-
return result.mapErr(original.intoAmplifyErrorOrThrow)
401-
}

0 commit comments

Comments
 (0)