From 1b8589b5c1671b9b0c812f0a71ee475561107464 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Thu, 11 Jul 2024 07:39:17 -0300 Subject: [PATCH] fix(auth): add missing nonce param when updating user --- Sources/Auth/Types.swift | 8 ++++++++ Tests/AuthTests/RequestsTests.swift | 1 + .../__Snapshots__/RequestsTests/testUpdateUser.1.txt | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/Auth/Types.swift b/Sources/Auth/Types.swift index 795415df..a5e536bf 100644 --- a/Sources/Auth/Types.swift +++ b/Sources/Auth/Types.swift @@ -465,6 +465,12 @@ public struct UserAttributes: Codable, Hashable, Sendable { public var phone: String? /// The user's password. public var password: String? + + /// The nonce sent for reauthentication if the user's password is to be updated. + /// + /// Note: Call ``AuthClient/reauthenticate()`` to obtain the nonce first. + public var nonce: String? + /// An email change token. public var emailChangeToken: String? /// 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 { email: String? = nil, phone: String? = nil, password: String? = nil, + nonce: String? = nil, emailChangeToken: String? = nil, data: [String: AnyJSON]? = nil ) { self.email = email self.phone = phone self.password = password + self.nonce = nonce self.emailChangeToken = emailChangeToken self.data = data } diff --git a/Tests/AuthTests/RequestsTests.swift b/Tests/AuthTests/RequestsTests.swift index 99000bd7..3ba5defc 100644 --- a/Tests/AuthTests/RequestsTests.swift +++ b/Tests/AuthTests/RequestsTests.swift @@ -284,6 +284,7 @@ final class RequestsTests: XCTestCase { email: "example@mail.com", phone: "+1 202-918-2132", password: "another.pass", + nonce: "abcdef", emailChangeToken: "123456", data: ["custom_key": .string("custom_value")] ) diff --git a/Tests/AuthTests/__Snapshots__/RequestsTests/testUpdateUser.1.txt b/Tests/AuthTests/__Snapshots__/RequestsTests/testUpdateUser.1.txt index ab59fdc7..a87cf430 100644 --- a/Tests/AuthTests/__Snapshots__/RequestsTests/testUpdateUser.1.txt +++ b/Tests/AuthTests/__Snapshots__/RequestsTests/testUpdateUser.1.txt @@ -4,5 +4,5 @@ curl \ --header "Authorization: Bearer accesstoken" \ --header "Content-Type: application/json" \ --header "X-Client-Info: gotrue-swift/x.y.z" \ - --data "{\"data\":{\"custom_key\":\"custom_value\"},\"email\":\"example@mail.com\",\"email_change_token\":\"123456\",\"password\":\"another.pass\",\"phone\":\"+1 202-918-2132\"}" \ + --data "{\"data\":{\"custom_key\":\"custom_value\"},\"email\":\"example@mail.com\",\"email_change_token\":\"123456\",\"nonce\":\"abcdef\",\"password\":\"another.pass\",\"phone\":\"+1 202-918-2132\"}" \ "http://localhost:54321/auth/v1/user" \ No newline at end of file