@@ -18,33 +18,29 @@ public struct AuthAdmin: Sendable {
1818 /// Get user by id.
1919 /// - Parameter uid: The user's unique identifier.
2020 /// - Note: This function should only be called on a server. Never expose your `service_role` key in the browser.
21- public func getUserById( _ uid: UUID ) async throws ( AuthError) -> User {
22- try await wrappingError ( or: mapToAuthError) {
23- try await self . api. execute (
24- self . configuration. url. appendingPathComponent ( " admin/users/ \( uid) " )
25- )
26- . serializingDecodable ( User . self, decoder: self . configuration. decoder)
27- . value
28- }
21+ public func getUserById( _ uid: UUID ) async throws -> User {
22+ try await self . api. execute (
23+ self . configuration. url. appendingPathComponent ( " admin/users/ \( uid) " )
24+ )
25+ . serializingDecodable ( User . self, decoder: self . configuration. decoder)
26+ . value
2927 }
3028
3129 /// Updates the user data.
3230 /// - Parameters:
3331 /// - uid: The user id you want to update.
3432 /// - attributes: The data you want to update.
3533 @discardableResult
36- public func updateUserById( _ uid: UUID , attributes: AdminUserAttributes ) async throws ( AuthError )
34+ public func updateUserById( _ uid: UUID , attributes: AdminUserAttributes ) async throws
3735 -> User
3836 {
39- try await wrappingError ( or: mapToAuthError) {
40- try await self . api. execute (
41- self . configuration. url. appendingPathComponent ( " admin/users/ \( uid) " ) ,
42- method: . put,
43- body: attributes
44- )
45- . serializingDecodable ( User . self, decoder: self . configuration. decoder)
46- . value
47- }
37+ try await self . api. execute (
38+ self . configuration. url. appendingPathComponent ( " admin/users/ \( uid) " ) ,
39+ method: . put,
40+ body: attributes
41+ )
42+ . serializingDecodable ( User . self, decoder: self . configuration. decoder)
43+ . value
4844 }
4945
5046 /// Creates a new user.
@@ -54,16 +50,14 @@ public struct AuthAdmin: Sendable {
5450 /// - If you are sure that the created user's email or phone number is legitimate and verified, you can set the ``AdminUserAttributes/emailConfirm`` or ``AdminUserAttributes/phoneConfirm`` param to true.
5551 /// - Warning: Never expose your `service_role` key on the client.
5652 @discardableResult
57- public func createUser( attributes: AdminUserAttributes ) async throws ( AuthError) -> User {
58- try await wrappingError ( or: mapToAuthError) {
59- try await self . api. execute (
60- self . configuration. url. appendingPathComponent ( " admin/users " ) ,
61- method: . post,
62- body: attributes
63- )
64- . serializingDecodable ( User . self, decoder: self . configuration. decoder)
65- . value
66- }
53+ public func createUser( attributes: AdminUserAttributes ) async throws -> User {
54+ try await self . api. execute (
55+ self . configuration. url. appendingPathComponent ( " admin/users " ) ,
56+ method: . post,
57+ body: attributes
58+ )
59+ . serializingDecodable ( User . self, decoder: self . configuration. decoder)
60+ . value
6761 }
6862
6963 /// Sends an invite link to an email address.
@@ -80,22 +74,20 @@ public struct AuthAdmin: Sendable {
8074 _ email: String ,
8175 data: [ String : AnyJSON ] ? = nil ,
8276 redirectTo: URL ? = nil
83- ) async throws ( AuthError) -> User {
84- try await wrappingError ( or: mapToAuthError) {
85- try await self . api. execute (
86- self . configuration. url. appendingPathComponent ( " admin/invite " ) ,
87- method: . post,
88- query: ( redirectTo ?? self . configuration. redirectToURL) . map {
89- [ " redirect_to " : $0. absoluteString]
90- } ,
91- body: [
92- " email " : . string( email) ,
93- " data " : data. map ( { AnyJSON . object ( $0) } ) ?? . null,
94- ]
95- )
96- . serializingDecodable ( User . self, decoder: self . configuration. decoder)
97- . value
98- }
77+ ) async throws -> User {
78+ try await self . api. execute (
79+ self . configuration. url. appendingPathComponent ( " admin/invite " ) ,
80+ method: . post,
81+ query: ( redirectTo ?? self . configuration. redirectToURL) . map {
82+ [ " redirect_to " : $0. absoluteString]
83+ } ,
84+ body: [
85+ " email " : . string( email) ,
86+ " data " : data. map ( { AnyJSON . object ( $0) } ) ?? . null,
87+ ]
88+ )
89+ . serializingDecodable ( User . self, decoder: self . configuration. decoder)
90+ . value
9991 }
10092
10193 /// Delete a user. Requires `service_role` key.
@@ -105,14 +97,12 @@ public struct AuthAdmin: Sendable {
10597 /// from the auth schema.
10698 ///
10799 /// - Warning: Never expose your `service_role` key on the client.
108- public func deleteUser( id: UUID , shouldSoftDelete: Bool = false ) async throws ( AuthError) {
109- _ = try await wrappingError ( or: mapToAuthError) {
110- try await self . api. execute (
111- self . configuration. url. appendingPathComponent ( " admin/users/ \( id) " ) ,
112- method: . delete,
113- body: DeleteUserRequest ( shouldSoftDelete: shouldSoftDelete)
114- ) . serializingData ( ) . value
115- }
100+ public func deleteUser( id: UUID , shouldSoftDelete: Bool = false ) async throws {
101+ _ = try await self . api. execute (
102+ self . configuration. url. appendingPathComponent ( " admin/users/ \( id) " ) ,
103+ method: . delete,
104+ body: DeleteUserRequest ( shouldSoftDelete: shouldSoftDelete)
105+ ) . serializingData ( ) . value
116106 }
117107
118108 /// Get a list of users.
@@ -122,51 +112,49 @@ public struct AuthAdmin: Sendable {
122112 /// - Warning: Never expose your `service_role` key in the client.
123113 public func listUsers(
124114 params: PageParams ? = nil
125- ) async throws ( AuthError ) -> ListUsersPaginatedResponse {
115+ ) async throws -> ListUsersPaginatedResponse {
126116 struct Response : Decodable {
127117 let users : [ User ]
128118 let aud : String
129119 }
130120
131- return try await wrappingError ( or: mapToAuthError) {
132- let httpResponse = try await self . api. execute (
133- self . configuration. url. appendingPathComponent ( " admin/users " ) ,
134- query: [
135- " page " : params? . page? . description ?? " " ,
136- " per_page " : params? . perPage? . description ?? " " ,
137- ]
138- )
139- . serializingDecodable ( Response . self, decoder: self . configuration. decoder)
140- . response
141-
142- let response = try httpResponse. result. get ( )
143-
144- var pagination = ListUsersPaginatedResponse (
145- users: response. users,
146- aud: response. aud,
147- lastPage: 0 ,
148- total: httpResponse. response? . headers [ " X-Total-Count " ] . flatMap ( Int . init) ?? 0
149- )
150-
151- let links =
152- httpResponse. response? . headers [ " Link " ] . flatMap { $0. components ( separatedBy: " , " ) } ?? [ ]
153- if !links. isEmpty {
154- for link in links {
155- let page = link. components ( separatedBy: " ; " ) [ 0 ] . components ( separatedBy: " = " ) [ 1 ] . prefix (
156- while: \. isNumber
157- )
158- let rel = link. components ( separatedBy: " ; " ) [ 1 ] . components ( separatedBy: " = " ) [ 1 ]
159-
160- if rel == " \" last \" " , let lastPage = Int ( page) {
161- pagination. lastPage = lastPage
162- } else if rel == " \" next \" " , let nextPage = Int ( page) {
163- pagination. nextPage = nextPage
164- }
121+ let httpResponse = try await self . api. execute (
122+ self . configuration. url. appendingPathComponent ( " admin/users " ) ,
123+ query: [
124+ " page " : params? . page? . description ?? " " ,
125+ " per_page " : params? . perPage? . description ?? " " ,
126+ ]
127+ )
128+ . serializingDecodable ( Response . self, decoder: self . configuration. decoder)
129+ . response
130+
131+ let response = try httpResponse. result. get ( )
132+
133+ var pagination = ListUsersPaginatedResponse (
134+ users: response. users,
135+ aud: response. aud,
136+ lastPage: 0 ,
137+ total: httpResponse. response? . headers [ " X-Total-Count " ] . flatMap ( Int . init) ?? 0
138+ )
139+
140+ let links =
141+ httpResponse. response? . headers [ " Link " ] . flatMap { $0. components ( separatedBy: " , " ) } ?? [ ]
142+ if !links. isEmpty {
143+ for link in links {
144+ let page = link. components ( separatedBy: " ; " ) [ 0 ] . components ( separatedBy: " = " ) [ 1 ] . prefix (
145+ while: \. isNumber
146+ )
147+ let rel = link. components ( separatedBy: " ; " ) [ 1 ] . components ( separatedBy: " = " ) [ 1 ]
148+
149+ if rel == " \" last \" " , let lastPage = Int ( page) {
150+ pagination. lastPage = lastPage
151+ } else if rel == " \" next \" " , let nextPage = Int ( page) {
152+ pagination. nextPage = nextPage
165153 }
166154 }
167-
168- return pagination
169155 }
156+
157+ return pagination
170158 }
171159
172160 /*
0 commit comments