Skip to content

Commit 8d0e236

Browse files
committed
comment generate link related code
1 parent 9bed99d commit 8d0e236

File tree

4 files changed

+208
-202
lines changed

4 files changed

+208
-202
lines changed

Sources/Auth/AuthAdmin.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ public struct AuthAdmin: Sendable {
153153
if !links.isEmpty {
154154
for link in links {
155155
let page = link.components(separatedBy: ";")[0].components(separatedBy: "=")[1].prefix(
156-
while: \.isNumber)
156+
while: \.isNumber
157+
)
157158
let rel = link.components(separatedBy: ";")[1].components(separatedBy: "=")[1]
158159

159160
if rel == "\"last\"", let lastPage = Int(page) {
@@ -167,6 +168,10 @@ public struct AuthAdmin: Sendable {
167168
return pagination
168169
}
169170

171+
/*
172+
Generate link is commented out temporarily due issues with they Auth's decoding is configured.
173+
Will revisit it later.
174+
170175
/// Generates email links and OTPs to be sent via a custom email provider.
171176
///
172177
/// - Parameter params: The parameters for the link generation.
@@ -190,6 +195,7 @@ public struct AuthAdmin: Sendable {
190195
)
191196
).decoded(decoder: configuration.decoder)
192197
}
198+
*/
193199
}
194200

195201
extension HTTPField.Name {

Sources/Auth/Types.swift

Lines changed: 120 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -909,123 +909,123 @@ public struct ListUsersPaginatedResponse: Hashable, Sendable {
909909
public var total: Int
910910
}
911911

912-
public struct GenerateLinkParams: Sendable {
913-
struct Body: Encodable {
914-
var type: GenerateLinkType
915-
var email: String
916-
var password: String?
917-
var newEmail: String?
918-
var data: [String: AnyJSON]?
919-
}
920-
var body: Body
921-
var redirectTo: URL?
922-
923-
/// Generates a signup link.
924-
public static func signUp(
925-
email: String,
926-
password: String,
927-
data: [String: AnyJSON]? = nil,
928-
redirectTo: URL? = nil
929-
) -> GenerateLinkParams {
930-
GenerateLinkParams(
931-
body: .init(
932-
type: .signup,
933-
email: email,
934-
password: password,
935-
data: data
936-
),
937-
redirectTo: redirectTo
938-
)
939-
}
940-
941-
/// Generates an invite link.
942-
public static func invite(
943-
email: String,
944-
data: [String: AnyJSON]? = nil,
945-
redirectTo: URL? = nil
946-
) -> GenerateLinkParams {
947-
GenerateLinkParams(
948-
body: .init(
949-
type: .invite,
950-
email: email,
951-
data: data
952-
),
953-
redirectTo: redirectTo
954-
)
955-
}
956-
957-
/// Generates a magic link.
958-
public static func magicLink(
959-
email: String,
960-
data: [String: AnyJSON]? = nil,
961-
redirectTo: URL? = nil
962-
) -> GenerateLinkParams {
963-
GenerateLinkParams(
964-
body: .init(
965-
type: .magiclink,
966-
email: email,
967-
data: data
968-
),
969-
redirectTo: redirectTo
970-
)
971-
}
972-
973-
/// Generates a recovery link.
974-
public static func recovery(
975-
email: String,
976-
redirectTo: URL? = nil
977-
) -> GenerateLinkParams {
978-
GenerateLinkParams(
979-
body: .init(
980-
type: .recovery,
981-
email: email
982-
),
983-
redirectTo: redirectTo
984-
)
985-
}
986-
987-
}
988-
989-
/// The response from the ``AuthAdmin/generateLink(params:)`` function.
990-
public struct GenerateLinkResponse: Hashable, Sendable, Decodable {
991-
/// The properties related to the email link generated.
992-
public let properties: GenerateLinkProperties
993-
/// The user that the email link is associated to.
994-
public let user: User
995-
996-
public init(from decoder: any Decoder) throws {
997-
self.properties = try GenerateLinkProperties(from: decoder)
998-
self.user = try User(from: decoder)
999-
}
1000-
}
1001-
1002-
/// The properties related to the email link generated.
1003-
public struct GenerateLinkProperties: Decodable, Hashable, Sendable {
1004-
/// The email link to send to the users.
1005-
/// The action link follows the following format: auth/v1/verify?type={verification_type}&token={hashed_token}&redirect_to={redirect_to}
1006-
public let actionLink: URL
1007-
/// The raw ramil OTP.
1008-
/// You should send this in the email if you want your users to verify using an OTP instead of the action link.
1009-
public let emailOTP: String
1010-
/// The hashed token appended to the action link.
1011-
public let hashedToken: String
1012-
/// The URL appended to the action link.
1013-
public let redirectTo: URL
1014-
/// The verification type that the emaillink is associated to.
1015-
public let verificationType: GenerateLinkType
1016-
}
1017-
1018-
public struct GenerateLinkType: RawRepresentable, Codable, Hashable, Sendable {
1019-
public let rawValue: String
1020-
1021-
public init(rawValue: String) {
1022-
self.rawValue = rawValue
1023-
}
1024-
1025-
public static let signup = GenerateLinkType(rawValue: "signup")
1026-
public static let invite = GenerateLinkType(rawValue: "invite")
1027-
public static let magiclink = GenerateLinkType(rawValue: "magiclink")
1028-
public static let recovery = GenerateLinkType(rawValue: "recovery")
1029-
public static let emailChangeCurrent = GenerateLinkType(rawValue: "email_change_current")
1030-
public static let emailChangeNew = GenerateLinkType(rawValue: "email_change_new")
1031-
}
912+
//public struct GenerateLinkParams: Sendable {
913+
// struct Body: Encodable {
914+
// var type: GenerateLinkType
915+
// var email: String
916+
// var password: String?
917+
// var newEmail: String?
918+
// var data: [String: AnyJSON]?
919+
// }
920+
// var body: Body
921+
// var redirectTo: URL?
922+
//
923+
// /// Generates a signup link.
924+
// public static func signUp(
925+
// email: String,
926+
// password: String,
927+
// data: [String: AnyJSON]? = nil,
928+
// redirectTo: URL? = nil
929+
// ) -> GenerateLinkParams {
930+
// GenerateLinkParams(
931+
// body: .init(
932+
// type: .signup,
933+
// email: email,
934+
// password: password,
935+
// data: data
936+
// ),
937+
// redirectTo: redirectTo
938+
// )
939+
// }
940+
//
941+
// /// Generates an invite link.
942+
// public static func invite(
943+
// email: String,
944+
// data: [String: AnyJSON]? = nil,
945+
// redirectTo: URL? = nil
946+
// ) -> GenerateLinkParams {
947+
// GenerateLinkParams(
948+
// body: .init(
949+
// type: .invite,
950+
// email: email,
951+
// data: data
952+
// ),
953+
// redirectTo: redirectTo
954+
// )
955+
// }
956+
//
957+
// /// Generates a magic link.
958+
// public static func magicLink(
959+
// email: String,
960+
// data: [String: AnyJSON]? = nil,
961+
// redirectTo: URL? = nil
962+
// ) -> GenerateLinkParams {
963+
// GenerateLinkParams(
964+
// body: .init(
965+
// type: .magiclink,
966+
// email: email,
967+
// data: data
968+
// ),
969+
// redirectTo: redirectTo
970+
// )
971+
// }
972+
//
973+
// /// Generates a recovery link.
974+
// public static func recovery(
975+
// email: String,
976+
// redirectTo: URL? = nil
977+
// ) -> GenerateLinkParams {
978+
// GenerateLinkParams(
979+
// body: .init(
980+
// type: .recovery,
981+
// email: email
982+
// ),
983+
// redirectTo: redirectTo
984+
// )
985+
// }
986+
//
987+
//}
988+
//
989+
///// The response from the ``AuthAdmin/generateLink(params:)`` function.
990+
//public struct GenerateLinkResponse: Hashable, Sendable, Decodable {
991+
// /// The properties related to the email link generated.
992+
// public let properties: GenerateLinkProperties
993+
// /// The user that the email link is associated to.
994+
// public let user: User
995+
//
996+
// public init(from decoder: any Decoder) throws {
997+
// self.properties = try GenerateLinkProperties(from: decoder)
998+
// self.user = try User(from: decoder)
999+
// }
1000+
//}
1001+
//
1002+
///// The properties related to the email link generated.
1003+
//public struct GenerateLinkProperties: Decodable, Hashable, Sendable {
1004+
// /// The email link to send to the users.
1005+
// /// The action link follows the following format: auth/v1/verify?type={verification_type}&token={hashed_token}&redirect_to={redirect_to}
1006+
// public let actionLink: URL
1007+
// /// The raw ramil OTP.
1008+
// /// You should send this in the email if you want your users to verify using an OTP instead of the action link.
1009+
// public let emailOTP: String
1010+
// /// The hashed token appended to the action link.
1011+
// public let hashedToken: String
1012+
// /// The URL appended to the action link.
1013+
// public let redirectTo: URL
1014+
// /// The verification type that the emaillink is associated to.
1015+
// public let verificationType: GenerateLinkType
1016+
//}
1017+
//
1018+
//public struct GenerateLinkType: RawRepresentable, Codable, Hashable, Sendable {
1019+
// public let rawValue: String
1020+
//
1021+
// public init(rawValue: String) {
1022+
// self.rawValue = rawValue
1023+
// }
1024+
//
1025+
// public static let signup = GenerateLinkType(rawValue: "signup")
1026+
// public static let invite = GenerateLinkType(rawValue: "invite")
1027+
// public static let magiclink = GenerateLinkType(rawValue: "magiclink")
1028+
// public static let recovery = GenerateLinkType(rawValue: "recovery")
1029+
// public static let emailChangeCurrent = GenerateLinkType(rawValue: "email_change_current")
1030+
// public static let emailChangeNew = GenerateLinkType(rawValue: "email_change_new")
1031+
//}

Tests/AuthTests/AuthClientTests.swift

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,46 +2043,46 @@ final class AuthClientTests: XCTestCase {
20432043
_ = try await sut.admin.createUser(attributes: attributes)
20442044
}
20452045

2046-
func testGenerateLink_signUp() async throws {
2047-
let sut = makeSUT()
2048-
2049-
let user = User(fromMockNamed: "user")
2050-
let encoder = JSONEncoder.supabase()
2051-
encoder.keyEncodingStrategy = .convertToSnakeCase
2052-
2053-
let userData = try encoder.encode(user)
2054-
var json = try JSONSerialization.jsonObject(with: userData, options: []) as! [String: Any]
2055-
2056-
json["action_link"] = "https://example.com/auth/v1/verify?type=signup&token={hashed_token}&redirect_to=https://example.com"
2057-
json["email_otp"] = "123456"
2058-
json["hashed_token"] = "hashed_token"
2059-
json["redirect_to"] = "https://example.com"
2060-
json["verification_type"] = "signup"
2061-
2062-
let responseData = try JSONSerialization.data(withJSONObject: json)
2063-
2064-
Mock(
2065-
url: clientURL.appendingPathComponent("admin/generate_link"),
2066-
statusCode: 200,
2067-
data: [
2068-
.post: responseData
2069-
]
2070-
)
2071-
.register()
2072-
2073-
let link = try await sut.admin.generateLink(
2074-
params: .signUp(
2075-
2076-
password: "password",
2077-
data: ["full_name": "John Doe"]
2078-
)
2079-
)
2080-
2081-
expectNoDifference(
2082-
link.properties.actionLink.absoluteString,
2083-
"https://example.com/auth/v1/verify?type=signup&token={hashed_token}&redirect_to=https://example.com".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
2084-
)
2085-
}
2046+
// func testGenerateLink_signUp() async throws {
2047+
// let sut = makeSUT()
2048+
//
2049+
// let user = User(fromMockNamed: "user")
2050+
// let encoder = JSONEncoder.supabase()
2051+
// encoder.keyEncodingStrategy = .convertToSnakeCase
2052+
//
2053+
// let userData = try encoder.encode(user)
2054+
// var json = try JSONSerialization.jsonObject(with: userData, options: []) as! [String: Any]
2055+
//
2056+
// json["action_link"] = "https://example.com/auth/v1/verify?type=signup&token={hashed_token}&redirect_to=https://example.com"
2057+
// json["email_otp"] = "123456"
2058+
// json["hashed_token"] = "hashed_token"
2059+
// json["redirect_to"] = "https://example.com"
2060+
// json["verification_type"] = "signup"
2061+
//
2062+
// let responseData = try JSONSerialization.data(withJSONObject: json)
2063+
//
2064+
// Mock(
2065+
// url: clientURL.appendingPathComponent("admin/generate_link"),
2066+
// statusCode: 200,
2067+
// data: [
2068+
// .post: responseData
2069+
// ]
2070+
// )
2071+
// .register()
2072+
//
2073+
// let link = try await sut.admin.generateLink(
2074+
// params: .signUp(
2075+
// email: "[email protected]",
2076+
// password: "password",
2077+
// data: ["full_name": "John Doe"]
2078+
// )
2079+
// )
2080+
//
2081+
// expectNoDifference(
2082+
// link.properties.actionLink.absoluteString,
2083+
// "https://example.com/auth/v1/verify?type=signup&token={hashed_token}&redirect_to=https://example.com".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
2084+
// )
2085+
// }
20862086

20872087
func testInviteUserByEmail() async throws {
20882088
let sut = makeSUT()

0 commit comments

Comments
 (0)