@@ -29,7 +29,7 @@ extension TurnkeyContext {
2929 }
3030 }
3131
32- /// Updates the currently authenticated user's contact information .
32+ /// Updates the contact information for the user associated with the currently selected session .
3333 ///
3434 /// - Parameters:
3535 /// - email: Optional email address to update.
@@ -63,4 +63,70 @@ extension TurnkeyContext {
6363 throw TurnkeySwiftError . failedToUpdateUser ( underlying: error)
6464 }
6565 }
66+
67+ /// Updates the email address for the user associated with the currently selected session.
68+ ///
69+ /// If a verification token is provided, the email will be marked as verified. Otherwise, it will be considered unverified.
70+ /// Passing an empty string ("") will delete the user's email address.
71+ ///
72+ /// - Parameters:
73+ /// - email: The new email address to update, or an empty string to delete it.
74+ /// - verificationToken: Optional verification token to mark the email as verified.
75+ ///
76+ /// - Throws: `TurnkeySwiftError.invalidSession` if no session is selected,
77+ /// or `TurnkeySwiftError.failedToUpdateUserEmail` if the update fails.
78+ public func updateUserEmail( email: String , verificationToken: String ? = nil ) async throws {
79+ guard let client, let user else {
80+ throw TurnkeySwiftError . invalidSession
81+ }
82+
83+ do {
84+ let resp = try await client. updateUserEmail (
85+ organizationId: user. organizationId,
86+ userId: user. id,
87+ userEmail: email,
88+ verificationToken: verificationToken
89+ )
90+
91+ if try resp. body. json. activity. result. updateUserEmailResult? . userId != nil {
92+ await refreshUser ( )
93+ }
94+
95+ } catch {
96+ throw TurnkeySwiftError . failedToUpdateUserEmail ( underlying: error)
97+ }
98+ }
99+
100+ /// Updates the phone number for the user associated with the currently selected session.
101+ ///
102+ /// If a verification token is provided, the phone number will be marked as verified. Otherwise, it will be considered unverified.
103+ /// Passing an empty string ("") will delete the user's phone number.
104+ ///
105+ /// - Parameters:
106+ /// - phone: The new phone number to update, or an empty string to delete it.
107+ /// - verificationToken: Optional verification token to mark the phone number as verified.
108+ ///
109+ /// - Throws: `TurnkeySwiftError.invalidSession` if no session is selected,
110+ /// or `TurnkeySwiftError.failedToUpdateUserPhoneNumber` if the update fails.
111+ public func updateUserPhoneNumber( phone: String , verificationToken: String ? = nil ) async throws {
112+ guard let client, let user else {
113+ throw TurnkeySwiftError . invalidSession
114+ }
115+
116+ do {
117+ let resp = try await client. updateUserPhoneNumber (
118+ organizationId: user. organizationId,
119+ userId: user. id,
120+ userPhoneNumber: phone,
121+ verificationToken: verificationToken
122+ )
123+
124+ if try resp. body. json. activity. result. updateUserPhoneNumberResult? . userId != nil {
125+ await refreshUser ( )
126+ }
127+
128+ } catch {
129+ throw TurnkeySwiftError . failedToUpdateUserPhoneNumber ( underlying: error)
130+ }
131+ }
66132}
0 commit comments