@@ -18,33 +18,29 @@ public struct AuthAdmin: Sendable {
18
18
/// Get user by id.
19
19
/// - Parameter uid: The user's unique identifier.
20
20
/// - 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
29
27
}
30
28
31
29
/// Updates the user data.
32
30
/// - Parameters:
33
31
/// - uid: The user id you want to update.
34
32
/// - attributes: The data you want to update.
35
33
@discardableResult
36
- public func updateUserById( _ uid: UUID , attributes: AdminUserAttributes ) async throws ( AuthError )
34
+ public func updateUserById( _ uid: UUID , attributes: AdminUserAttributes ) async throws
37
35
-> User
38
36
{
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
48
44
}
49
45
50
46
/// Creates a new user.
@@ -54,16 +50,14 @@ public struct AuthAdmin: Sendable {
54
50
/// - 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.
55
51
/// - Warning: Never expose your `service_role` key on the client.
56
52
@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
67
61
}
68
62
69
63
/// Sends an invite link to an email address.
@@ -80,22 +74,20 @@ public struct AuthAdmin: Sendable {
80
74
_ email: String ,
81
75
data: [ String : AnyJSON ] ? = nil ,
82
76
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
99
91
}
100
92
101
93
/// Delete a user. Requires `service_role` key.
@@ -105,14 +97,12 @@ public struct AuthAdmin: Sendable {
105
97
/// from the auth schema.
106
98
///
107
99
/// - 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
116
106
}
117
107
118
108
/// Get a list of users.
@@ -122,51 +112,49 @@ public struct AuthAdmin: Sendable {
122
112
/// - Warning: Never expose your `service_role` key in the client.
123
113
public func listUsers(
124
114
params: PageParams ? = nil
125
- ) async throws ( AuthError ) -> ListUsersPaginatedResponse {
115
+ ) async throws -> ListUsersPaginatedResponse {
126
116
struct Response : Decodable {
127
117
let users : [ User ]
128
118
let aud : String
129
119
}
130
120
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
165
153
}
166
154
}
167
-
168
- return pagination
169
155
}
156
+
157
+ return pagination
170
158
}
171
159
172
160
/*
0 commit comments