belt 0.3.14 → 0.3.15
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/lib/belt/version.rb +1 -1
- data/lib/templates/generate/auth/frontend/auth.js +22 -9
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 491ae37769b6a21cfd1823301d425d0af0b3f1e3c19952b909febebc7f2c3b32
|
|
4
|
+
data.tar.gz: a2427f68a34d38be0cf3af42ac33a8d3c3d190f36505c54ef531219cd0c3fb66
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 895fb4f7238141ba4752cdfc9200c44b2ef870bbc61585a436d3a9e36f39c689e8429d97ad4cf0101d92cbea06b3771864c1d31e4892dae54448a2f0e8ec138b
|
|
7
|
+
data.tar.gz: 4b2fee884c2f7ad9ba78bd7a46dacf75d1d5c8aa5da43d151ab7d03889aa740dd60a12a1fce5c18467f7c3bbb54aacb886a55efdcc58a997ed6367148ea37f15
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.15
|
|
4
|
+
|
|
5
|
+
### Bug Fix
|
|
6
|
+
|
|
7
|
+
- **`belt generate auth` NEW_PASSWORD_REQUIRED challenge sent `email` even when
|
|
8
|
+
the user already had it**: The 0.3.14 fix always passed `{ email }` to
|
|
9
|
+
`completeNewPasswordChallenge`. That fixed pools where `email` was missing, but
|
|
10
|
+
broke the common case where the user already has `email` set (e.g. created via
|
|
11
|
+
`admin-create-user` with an email) — Cognito rejects that with a 400
|
|
12
|
+
`NotAuthorizedException: Cannot modify an already provided email`. The template
|
|
13
|
+
now reads the `requiredAttributes` list Cognito provides in the
|
|
14
|
+
`newPasswordRequired` callback and supplies `email` **only when Cognito actually
|
|
15
|
+
requires it**. Users with email already set complete the challenge without
|
|
16
|
+
re-sending it; users missing email still get it supplied. Handles both cases.
|
|
17
|
+
|
|
3
18
|
## 0.3.14
|
|
4
19
|
|
|
5
20
|
### Bug Fix
|
data/lib/belt/version.rb
CHANGED
|
@@ -37,41 +37,54 @@ export function signIn(username, password) {
|
|
|
37
37
|
resolve({ success: true })
|
|
38
38
|
},
|
|
39
39
|
onFailure: (err) => reject(err),
|
|
40
|
-
newPasswordRequired: () => {
|
|
41
|
-
// Stash the user
|
|
40
|
+
newPasswordRequired: (_userAttributes, requiredAttributes) => {
|
|
41
|
+
// Stash the user + the attributes Cognito actually requires so
|
|
42
|
+
// completeNewPassword can continue the SRP session and supply exactly
|
|
43
|
+
// what the pool asks for — no more, no less.
|
|
42
44
|
pendingUser = cognitoUser
|
|
45
|
+
pendingRequiredAttributes = requiredAttributes || []
|
|
43
46
|
resolve({ challenge: 'NEW_PASSWORD_REQUIRED' })
|
|
44
47
|
}
|
|
45
48
|
})
|
|
46
49
|
})
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
// Holds the CognitoUser mid-challenge for the NEW_PASSWORD_REQUIRED flow
|
|
52
|
+
// Holds the CognitoUser mid-challenge for the NEW_PASSWORD_REQUIRED flow,
|
|
53
|
+
// plus the list of attributes Cognito flagged as required for the challenge.
|
|
50
54
|
let pendingUser = null
|
|
55
|
+
let pendingRequiredAttributes = []
|
|
51
56
|
|
|
52
57
|
export function completeNewPassword(email, newPassword) {
|
|
53
58
|
if (!pendingUser) {
|
|
54
59
|
return Promise.reject(new Error('No pending password challenge. Sign in again.'))
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
+
// Only supply attributes Cognito actually asks for in this challenge.
|
|
63
|
+
// - If the pool requires `email` and the user doesn't have it yet, it shows
|
|
64
|
+
// up in requiredAttributes → we send it (username is the email). Skipping
|
|
65
|
+
// it would fail with "Invalid attributes given, email is missing".
|
|
66
|
+
// - If the user already has `email` (e.g. admin-created with it), it is NOT
|
|
67
|
+
// in requiredAttributes → we must NOT send it, or Cognito rejects with
|
|
68
|
+
// "Cannot modify an already provided email".
|
|
69
|
+
const attributes = {}
|
|
70
|
+
if (pendingRequiredAttributes.includes('email')) {
|
|
71
|
+
attributes.email = email
|
|
72
|
+
}
|
|
62
73
|
|
|
63
74
|
return new Promise((resolve, reject) => {
|
|
64
|
-
pendingUser.completeNewPasswordChallenge(newPassword,
|
|
75
|
+
pendingUser.completeNewPasswordChallenge(newPassword, attributes, {
|
|
65
76
|
onSuccess: (session) => {
|
|
66
77
|
setTokens({
|
|
67
78
|
IdToken: session.getIdToken().getJwtToken(),
|
|
68
79
|
RefreshToken: session.getRefreshToken().getToken()
|
|
69
80
|
})
|
|
70
81
|
pendingUser = null
|
|
82
|
+
pendingRequiredAttributes = []
|
|
71
83
|
resolve({ success: true })
|
|
72
84
|
},
|
|
73
85
|
onFailure: (err) => {
|
|
74
86
|
pendingUser = null
|
|
87
|
+
pendingRequiredAttributes = []
|
|
75
88
|
reject(err)
|
|
76
89
|
}
|
|
77
90
|
})
|