wirejs-deploy-amplify-basic 0.0.36 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,4 @@ export const auth = defineAuth({
5
5
  loginWith: {
6
6
  email: true,
7
7
  },
8
- access: allow => [
9
- allow.resource(api).to(['manageUsers', 'listUsers'])
10
- ]
11
8
  });
@@ -20,7 +20,6 @@ const backend = defineBackend({
20
20
  /**
21
21
  * Amplify resource augmentations
22
22
  */
23
-
24
23
  const userPoolClient = backend.auth.resources.cfnResources.cfnUserPoolClient;
25
24
  userPoolClient.explicitAuthFlows = userPoolClient.explicitAuthFlows || [];
26
25
  userPoolClient.explicitAuthFlows.push(
@@ -45,9 +44,9 @@ bucket.grantReadWrite(backend.api.resources.lambda);
45
44
  backend.api.addEnvironment(
46
45
  'BUCKET', bucket.bucketName,
47
46
  );
48
- // backend.api.addEnvironment(
49
- // 'COGNITO_CLIENT_ID', backend.auth.resources.userPoolClient.userPoolClientId
50
- // );
47
+ backend.api.addEnvironment(
48
+ 'COGNITO_CLIENT_ID', backend.auth.resources.userPoolClient.userPoolClientId
49
+ );
51
50
 
52
51
 
53
52
  /**
@@ -212,10 +212,7 @@ export class AuthenticationService extends AuthenticationServiceBase {
212
212
  state: 'unauthenticated',
213
213
  user: undefined,
214
214
  substate: 'pending-completesignup',
215
- metadata: JSON.stringify({
216
- email: form.inputs.email,
217
- sub: result.UserSub,
218
- })
215
+ metadata: form.inputs.email
219
216
  });
220
217
  return this.getMachineState(cookies);
221
218
  }
@@ -274,8 +271,8 @@ export class AuthenticationService extends AuthenticationServiceBase {
274
271
  return this.getMachineState(cookies);
275
272
  }
276
273
  try {
277
- const { email, sub } = JSON.parse(state.metadata);
278
- if (!email || !sub) {
274
+ const email = state.metadata;
275
+ if (!email) {
279
276
  this.#cookie.clear(cookies);
280
277
  return this.getMachineState(cookies);
281
278
  }
@@ -284,11 +281,21 @@ export class AuthenticationService extends AuthenticationServiceBase {
284
281
  Username: email,
285
282
  ConfirmationCode: form.inputs.code
286
283
  });
287
- await client.send(command);
284
+ const result = await client.send(command);
285
+ const signinCommand = new InitiateAuthCommand({
286
+ ClientId,
287
+ AuthFlow: 'USER_AUTH',
288
+ Session: result.Session
289
+ });
290
+ const signinResult = await client.send(signinCommand);
291
+ signinResult.AuthenticationResult?.AccessToken;
292
+ const jwtPayload = jose.decodeJwt(
293
+ // assuming for now, until we support challenges like OTP, Email code, etc.
294
+ signinResult.AuthenticationResult?.IdToken);
288
295
  await this.#cookie.write(cookies, {
289
296
  state: 'authenticated',
290
297
  user: {
291
- id: sub,
298
+ id: jwtPayload.sub,
292
299
  displayName: email,
293
300
  username: email,
294
301
  }
@@ -325,18 +332,38 @@ export class AuthenticationService extends AuthenticationServiceBase {
325
332
  state: 'authenticated',
326
333
  user: {
327
334
  id: jwtPayload.sub,
328
- username: jwtPayload['cognito:username'],
329
- displayName: jwtPayload['cognito:username'],
335
+ username: form.inputs.email,
336
+ displayName: form.inputs.email,
330
337
  },
331
338
  });
332
339
  return this.getMachineState(cookies);
333
340
  }
334
341
  catch (error) {
335
- return {
336
- errors: [{
337
- message: error.message
338
- }]
339
- };
342
+ if (error.message === 'User is not confirmed.') {
343
+ const command = new ResendConfirmationCodeCommand({
344
+ ClientId,
345
+ Username: form.inputs.email
346
+ });
347
+ await client.send(command);
348
+ await this.#cookie.write(cookies, {
349
+ state: 'unauthenticated',
350
+ user: undefined,
351
+ substate: 'pending-completesignup',
352
+ metadata: form.inputs.email,
353
+ });
354
+ return {
355
+ ...this.getMachineState(cookies),
356
+ message: `Your account setup isn't complete.<br />
357
+ We sent you a new code to enter below.`
358
+ };
359
+ }
360
+ else {
361
+ return {
362
+ errors: [{
363
+ message: error.message
364
+ }]
365
+ };
366
+ }
340
367
  }
341
368
  }
342
369
  else if (isAction(form, 'changepassword')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirejs-deploy-amplify-basic",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",