Skip to content

Commit a087a6a

Browse files
authored
fix(auth): add missing nonce param when updating user (#457)
1 parent 3e45b5a commit a087a6a

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Sources/Auth/Types.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,12 @@ public struct UserAttributes: Codable, Hashable, Sendable {
465465
public var phone: String?
466466
/// The user's password.
467467
public var password: String?
468+
469+
/// The nonce sent for reauthentication if the user's password is to be updated.
470+
///
471+
/// Note: Call ``AuthClient/reauthenticate()`` to obtain the nonce first.
472+
public var nonce: String?
473+
468474
/// An email change token.
469475
public var emailChangeToken: String?
470476
/// A custom data object to store the user's metadata. This maps to the `auth.users.user_metadata`
@@ -479,12 +485,14 @@ public struct UserAttributes: Codable, Hashable, Sendable {
479485
email: String? = nil,
480486
phone: String? = nil,
481487
password: String? = nil,
488+
nonce: String? = nil,
482489
emailChangeToken: String? = nil,
483490
data: [String: AnyJSON]? = nil
484491
) {
485492
self.email = email
486493
self.phone = phone
487494
self.password = password
495+
self.nonce = nonce
488496
self.emailChangeToken = emailChangeToken
489497
self.data = data
490498
}

Tests/AuthTests/RequestsTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ final class RequestsTests: XCTestCase {
284284
285285
phone: "+1 202-918-2132",
286286
password: "another.pass",
287+
nonce: "abcdef",
287288
emailChangeToken: "123456",
288289
data: ["custom_key": .string("custom_value")]
289290
)

Tests/AuthTests/__Snapshots__/RequestsTests/testUpdateUser.1.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ curl \
44
--header "Authorization: Bearer accesstoken" \
55
--header "Content-Type: application/json" \
66
--header "X-Client-Info: gotrue-swift/x.y.z" \
7-
--data "{\"data\":{\"custom_key\":\"custom_value\"},\"email\":\"[email protected]\",\"email_change_token\":\"123456\",\"password\":\"another.pass\",\"phone\":\"+1 202-918-2132\"}" \
7+
--data "{\"data\":{\"custom_key\":\"custom_value\"},\"email\":\"[email protected]\",\"email_change_token\":\"123456\",\"nonce\":\"abcdef\",\"password\":\"another.pass\",\"phone\":\"+1 202-918-2132\"}" \
88
"http://localhost:54321/auth/v1/user"

0 commit comments

Comments
 (0)