Skip to content

Commit 0967834

Browse files
committed
format
1 parent eaffb03 commit 0967834

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+359
-265
lines changed

Sources/Auth/AuthAdmin.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77

88
import Foundation
9-
import Helpers
109
import HTTPTypes
10+
import Helpers
1111

1212
public struct AuthAdmin: Sendable {
1313
let clientID: AuthClientID
@@ -71,7 +71,10 @@ public struct AuthAdmin: Sendable {
7171
let links = response.headerFields[.link]?.components(separatedBy: ",") ?? []
7272
if !links.isEmpty {
7373
for link in links {
74-
let page = link.components(separatedBy: ";")[0].components(separatedBy: "=")[1].prefix(while: \.isNumber)
74+
let page = link
75+
.components(separatedBy: ";")[0]
76+
.components(separatedBy: "=")[1]
77+
.prefix(while: \.isNumber)
7578
let rel = link.components(separatedBy: ";")[1].components(separatedBy: "=")[1]
7679

7780
if rel == "\"last\"", let lastPage = Int(page) {

Sources/Auth/AuthClient.swift

Lines changed: 77 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ConcurrencyExtras
22
import Foundation
3-
import Helpers
43
import HTTPTypes
4+
import Helpers
55

66
#if canImport(AuthenticationServices)
77
import AuthenticationServices
@@ -219,14 +219,15 @@ public final class AuthClient: Sendable {
219219
method: .post,
220220
url: configuration.url
221221
.appendingPathComponent("signup")
222-
.appendingQueryItems([
223-
(redirectTo ?? configuration.redirectToURL).map {
224-
URLQueryItem(
225-
name: "redirect_to",
226-
value: $0.absoluteString
227-
)
228-
}
229-
].compactMap { $0 })
222+
.appendingQueryItems(
223+
[
224+
(redirectTo ?? configuration.redirectToURL).map {
225+
URLQueryItem(
226+
name: "redirect_to",
227+
value: $0.absoluteString
228+
)
229+
}
230+
].compactMap { $0 })
230231
),
231232
from: configuration.encoder.encode(
232233
SignUpRequest(
@@ -270,9 +271,12 @@ public final class AuthClient: Sendable {
270271
)
271272
}
272273

273-
private func _signUp(for request: HTTPRequest, from bodyData: Data?) async throws -> AuthResponse {
274+
private func _signUp(
275+
for request: HTTPRequest,
276+
from bodyData: Data?
277+
) async throws -> AuthResponse {
274278
let (data, _) = try await api.execute(for: request, from: bodyData)
275-
279+
276280
let response = try configuration.decoder.decode(AuthResponse.self, from: data)
277281

278282
if let session = response.session {
@@ -381,7 +385,7 @@ public final class AuthClient: Sendable {
381385

382386
private func _signIn(for request: HTTPRequest, from bodyData: Data?) async throws -> Session {
383387
let (data, _) = try await api.execute(for: request, from: bodyData)
384-
388+
385389
let session = try configuration.decoder.decode(Session.self, from: data)
386390

387391
await sessionManager.update(session)
@@ -415,14 +419,15 @@ public final class AuthClient: Sendable {
415419
method: .post,
416420
url: configuration.url
417421
.appendingPathComponent("otp")
418-
.appendingQueryItems([
419-
(redirectTo ?? configuration.redirectToURL).map {
420-
URLQueryItem(
421-
name: "redirect_to",
422-
value: $0.absoluteString
423-
)
424-
}
425-
].compactMap { $0 })
422+
.appendingQueryItems(
423+
[
424+
(redirectTo ?? configuration.redirectToURL).map {
425+
URLQueryItem(
426+
name: "redirect_to",
427+
value: $0.absoluteString
428+
)
429+
}
430+
].compactMap { $0 })
426431
),
427432
from: configuration.encoder.encode(
428433
OTPParams(
@@ -500,7 +505,7 @@ public final class AuthClient: Sendable {
500505
)
501506
)
502507
)
503-
508+
504509
return try configuration.decoder.decode(SSOResponse.self, from: data)
505510
}
506511

@@ -534,7 +539,7 @@ public final class AuthClient: Sendable {
534539
)
535540
)
536541
)
537-
542+
538543
return try configuration.decoder.decode(SSOResponse.self, from: data)
539544
}
540545

@@ -561,7 +566,7 @@ public final class AuthClient: Sendable {
561566
]
562567
)
563568
)
564-
569+
565570
let session = try configuration.decoder.decode(Session.self, from: data)
566571

567572
codeVerifierStorage.set(nil)
@@ -813,9 +818,9 @@ public final class AuthClient: Sendable {
813818
),
814819
from: nil
815820
)
816-
821+
817822
let user = try configuration.decoder.decode(User.self, from: data)
818-
823+
819824
let session = Session(
820825
providerToken: providerToken,
821826
providerRefreshToken: providerRefreshToken,
@@ -924,7 +929,7 @@ public final class AuthClient: Sendable {
924929
from: nil
925930
)
926931
} catch let AuthError.api(_, _, _, response)
927-
where [404, 403, 401].contains(response.status.code)
932+
where [404, 403, 401].contains(response.status.code)
928933
{
929934
// ignore 404s since user might not exist anymore
930935
// ignore 401s, and 403s since an invalid or expired JWT should sign out the current session.
@@ -945,15 +950,16 @@ public final class AuthClient: Sendable {
945950
method: .post,
946951
url: configuration.url
947952
.appendingPathComponent("verify")
948-
.appendingQueryItems([
949-
(redirectTo ?? configuration.redirectToURL).map {
950-
URLQueryItem(
951-
name: "redirect_to",
952-
value: $0.absoluteString
953-
)
954-
}
955-
].compactMap { $0 })
956-
),
953+
.appendingQueryItems(
954+
[
955+
(redirectTo ?? configuration.redirectToURL).map {
956+
URLQueryItem(
957+
name: "redirect_to",
958+
value: $0.absoluteString
959+
)
960+
}
961+
].compactMap { $0 })
962+
),
957963
from: configuration.encoder.encode(
958964
VerifyOTPParams.email(
959965
VerifyEmailOTPParams(
@@ -1012,9 +1018,12 @@ public final class AuthClient: Sendable {
10121018
)
10131019
}
10141020

1015-
private func _verifyOTP(for request: HTTPRequest, from bodyData: Data?) async throws -> AuthResponse {
1021+
private func _verifyOTP(
1022+
for request: HTTPRequest,
1023+
from bodyData: Data?
1024+
) async throws -> AuthResponse {
10161025
let (data, _) = try await api.execute(for: request, from: bodyData)
1017-
1026+
10181027
let response = try configuration.decoder.decode(AuthResponse.self, from: data)
10191028

10201029
if let session = response.session {
@@ -1040,14 +1049,15 @@ public final class AuthClient: Sendable {
10401049
method: .post,
10411050
url: configuration.url
10421051
.appendingPathComponent("resend")
1043-
.appendingQueryItems([
1044-
(emailRedirectTo ?? configuration.redirectToURL).map {
1045-
URLQueryItem(
1046-
name: "redirect_to",
1047-
value: $0.absoluteString
1048-
)
1049-
}
1050-
].compactMap { $0 })
1052+
.appendingQueryItems(
1053+
[
1054+
(emailRedirectTo ?? configuration.redirectToURL).map {
1055+
URLQueryItem(
1056+
name: "redirect_to",
1057+
value: $0.absoluteString
1058+
)
1059+
}
1060+
].compactMap { $0 })
10511061
),
10521062
from: configuration.encoder.encode(
10531063
ResendEmailParams(
@@ -1084,7 +1094,7 @@ public final class AuthClient: Sendable {
10841094
)
10851095
)
10861096
)
1087-
1097+
10881098
return try configuration.decoder.decode(ResendMobileResponse.self, from: data)
10891099
}
10901100

@@ -1113,7 +1123,7 @@ public final class AuthClient: Sendable {
11131123
if let jwt {
11141124
request.headerFields[.authorization] = "Bearer \(jwt)"
11151125
}
1116-
1126+
11171127
let (data, _) = try await api.authorizedExecute(for: request, from: nil)
11181128
return try configuration.decoder.decode(User.self, from: data)
11191129
}
@@ -1135,20 +1145,21 @@ public final class AuthClient: Sendable {
11351145
method: .put,
11361146
url: configuration.url
11371147
.appendingPathComponent("user")
1138-
.appendingQueryItems([
1139-
(redirectTo ?? configuration.redirectToURL).map {
1140-
URLQueryItem(
1141-
name: "redirect_to",
1142-
value: $0.absoluteString
1143-
)
1144-
}
1145-
].compactMap { $0 })
1148+
.appendingQueryItems(
1149+
[
1150+
(redirectTo ?? configuration.redirectToURL).map {
1151+
URLQueryItem(
1152+
name: "redirect_to",
1153+
value: $0.absoluteString
1154+
)
1155+
}
1156+
].compactMap { $0 })
11461157
),
11471158
from: configuration.encoder.encode(user)
11481159
)
1149-
1160+
11501161
let updatedUser = try configuration.decoder.decode(User.self, from: data)
1151-
1162+
11521163
session.user = updatedUser
11531164
await sessionManager.update(session)
11541165
eventEmitter.emit(.userUpdated, session: session)
@@ -1279,14 +1290,15 @@ public final class AuthClient: Sendable {
12791290
method: .post,
12801291
url: configuration.url
12811292
.appendingPathComponent("recover")
1282-
.appendingQueryItems([
1283-
(redirectTo ?? configuration.redirectToURL).map {
1284-
URLQueryItem(
1285-
name: "redirect_to",
1286-
value: $0.absoluteString
1287-
)
1288-
}
1289-
].compactMap { $0 })
1293+
.appendingQueryItems(
1294+
[
1295+
(redirectTo ?? configuration.redirectToURL).map {
1296+
URLQueryItem(
1297+
name: "redirect_to",
1298+
value: $0.absoluteString
1299+
)
1300+
}
1301+
].compactMap { $0 })
12901302
),
12911303
from: configuration.encoder.encode(
12921304
RecoverParams(

Sources/Auth/AuthClientConfiguration.swift

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
//
77

88
import Foundation
9-
import Helpers
109
import HTTPTypes
1110
import HTTPTypesFoundation
11+
import Helpers
1212

1313
#if canImport(FoundationNetworking)
1414
import FoundationNetworking
@@ -25,31 +25,31 @@ extension AuthClient {
2525
public struct Configuration: Sendable {
2626
/// The URL of the Auth server.
2727
public let url: URL
28-
28+
2929
/// Any additional headers to send to the Auth server.
3030
public var headers: HTTPFields
3131
public let flowType: AuthFlowType
32-
32+
3333
/// Default URL to be used for redirect on the flows that requires it.
3434
public let redirectToURL: URL?
35-
35+
3636
/// Optional key name used for storing tokens in local storage.
3737
public var storageKey: String?
38-
38+
3939
/// Provider your own local storage implementation to use instead of the default one.
4040
public let localStorage: any AuthLocalStorage
41-
41+
4242
/// Custom SupabaseLogger implementation used to inspecting log messages from the Auth library.
4343
public let logger: (any SupabaseLogger)?
4444
public let encoder: JSONEncoder
4545
public let decoder: JSONDecoder
46-
46+
4747
/// A custom fetch implementation.
4848
public let fetch: FetchHandler
49-
49+
5050
/// Set to `true` if you want to automatically refresh the token before expiring.
5151
public let autoRefreshToken: Bool
52-
52+
5353
/// Initializes a AuthClient Configuration with optional parameters.
5454
///
5555
/// - Parameters:
@@ -65,23 +65,23 @@ extension AuthClient {
6565
/// - fetch: The asynchronous fetch handler for network requests.
6666
/// - autoRefreshToken: Set to `true` if you want to automatically refresh the token before expiring.
6767
public init(
68-
url: URL? = nil,
69-
headers: HTTPFields = [:],
70-
flowType: AuthFlowType = Configuration.defaultFlowType,
71-
redirectToURL: URL? = nil,
72-
storageKey: String? = nil,
73-
localStorage: any AuthLocalStorage,
74-
logger: (any SupabaseLogger)? = nil,
75-
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
76-
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
77-
fetch: @escaping FetchHandler = { request, bodyData in
78-
if let bodyData {
79-
try await URLSession.shared.upload(for: request, from: bodyData)
80-
} else {
81-
try await URLSession.shared.data(for: request)
82-
}
83-
},
84-
autoRefreshToken: Bool = AuthClient.Configuration.defaultAutoRefreshToken
68+
url: URL? = nil,
69+
headers: HTTPFields = [:],
70+
flowType: AuthFlowType = Configuration.defaultFlowType,
71+
redirectToURL: URL? = nil,
72+
storageKey: String? = nil,
73+
localStorage: any AuthLocalStorage,
74+
logger: (any SupabaseLogger)? = nil,
75+
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
76+
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
77+
fetch: @escaping FetchHandler = { request, bodyData in
78+
if let bodyData {
79+
try await URLSession.shared.upload(for: request, from: bodyData)
80+
} else {
81+
try await URLSession.shared.data(for: request)
82+
}
83+
},
84+
autoRefreshToken: Bool = AuthClient.Configuration.defaultAutoRefreshToken
8585
) {
8686
let headers = headers.merging(with: Configuration.defaultHeaders)
8787

Sources/Auth/AuthError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
2-
import Helpers
32
import HTTPTypes
3+
import Helpers
44

55
#if canImport(FoundationNetworking)
66
import FoundationNetworking

0 commit comments

Comments
 (0)