@@ -143,6 +143,31 @@ public struct User: Codable, Hashable, Identifiable, Sendable {
143
143
public var isAnonymous : Bool
144
144
public var factors : [ Factor ] ?
145
145
146
+ enum CodingKeys : String , CodingKey {
147
+ case id
148
+ case appMetadata = " app_metadata "
149
+ case userMetadata = " user_metadata "
150
+ case aud
151
+ case confirmationSentAt = " confirmation_sent_at "
152
+ case recoverySentAt = " recovery_sent_at "
153
+ case emailChangeSentAt = " email_change_sent_at "
154
+ case newEmail = " new_email "
155
+ case invitedAt = " invited_at "
156
+ case actionLink = " action_link "
157
+ case email
158
+ case phone
159
+ case createdAt = " created_at "
160
+ case confirmedAt = " confirmed_at "
161
+ case emailConfirmedAt = " email_confirmed_at "
162
+ case phoneConfirmedAt = " phone_confirmed_at "
163
+ case lastSignInAt = " last_sign_in_at "
164
+ case role
165
+ case updatedAt = " updated_at "
166
+ case identities
167
+ case isAnonymous = " is_anonymous "
168
+ case factors
169
+ }
170
+
146
171
public init (
147
172
id: UUID ,
148
173
appMetadata: [ String : AnyJSON ] ,
@@ -229,6 +254,17 @@ public struct UserIdentity: Codable, Hashable, Identifiable, Sendable {
229
254
public var lastSignInAt : Date ?
230
255
public var updatedAt : Date ?
231
256
257
+ enum CodingKeys : String , CodingKey {
258
+ case id
259
+ case identityId = " identity_id "
260
+ case userId = " user_id "
261
+ case identityData = " identity_data "
262
+ case provider
263
+ case createdAt = " created_at "
264
+ case lastSignInAt = " last_sign_in_at "
265
+ case updatedAt = " updated_at "
266
+ }
267
+
232
268
public init (
233
269
id: String ,
234
270
identityId: UUID ,
@@ -249,17 +285,6 @@ public struct UserIdentity: Codable, Hashable, Identifiable, Sendable {
249
285
self . updatedAt = updatedAt
250
286
}
251
287
252
- private enum CodingKeys : CodingKey {
253
- case id
254
- case identityId
255
- case userId
256
- case identityData
257
- case provider
258
- case createdAt
259
- case lastSignInAt
260
- case updatedAt
261
- }
262
-
263
288
public init ( from decoder: any Decoder ) throws {
264
289
let container = try decoder. container ( keyedBy: CodingKeys . self)
265
290
@@ -909,64 +934,126 @@ public struct ListUsersPaginatedResponse: Hashable, Sendable {
909
934
public var total : Int
910
935
}
911
936
912
- public struct GenerateLinkParams {
913
- var type : String
914
- var email : String
915
- var password : String ?
916
- var newEmail : String ?
917
- var data : [ String : AnyJSON ] ?
937
+ public struct GenerateLinkParams : Sendable {
938
+ struct Body : Encodable {
939
+ var type : GenerateLinkType
940
+ var email : String
941
+ var password : String ?
942
+ var newEmail : String ?
943
+ var data : [ String : AnyJSON ] ?
944
+ }
945
+ var body : Body
918
946
var redirectTo : URL ?
919
947
948
+ /// Generates a signup link.
920
949
public static func signUp(
921
950
email: String ,
922
951
password: String ,
923
952
data: [ String : AnyJSON ] ? = nil ,
924
953
redirectTo: URL ? = nil
925
954
) -> GenerateLinkParams {
926
955
GenerateLinkParams (
927
- type: " signup " ,
928
- email: email,
929
- password: password,
930
- data: data,
956
+ body: . init(
957
+ type: . signup,
958
+ email: email,
959
+ password: password,
960
+ data: data
961
+ ) ,
931
962
redirectTo: redirectTo
932
963
)
933
964
}
934
965
966
+ /// Generates an invite link.
935
967
public static func invite(
936
968
email: String ,
937
- data: [ String : AnyJSON ] ? ,
938
- redirectTo: URL ?
969
+ data: [ String : AnyJSON ] ? = nil ,
970
+ redirectTo: URL ? = nil
939
971
) -> GenerateLinkParams {
940
972
GenerateLinkParams (
941
- type: " invite " ,
942
- email: email,
943
- data: data,
973
+ body: . init(
974
+ type: . invite,
975
+ email: email,
976
+ data: data
977
+ ) ,
944
978
redirectTo: redirectTo
945
979
)
946
980
}
947
981
982
+ /// Generates a magic link.
948
983
public static func magicLink(
949
984
email: String ,
950
- data: [ String : AnyJSON ] ? ,
951
- redirectTo: URL ?
985
+ data: [ String : AnyJSON ] ? = nil ,
986
+ redirectTo: URL ? = nil
952
987
) -> GenerateLinkParams {
953
988
GenerateLinkParams (
954
- type: " magiclink " ,
955
- email: email,
956
- data: data,
989
+ body: . init(
990
+ type: . magiclink,
991
+ email: email,
992
+ data: data
993
+ ) ,
957
994
redirectTo: redirectTo
958
995
)
959
996
}
960
997
998
+ /// Generates a recovery link.
961
999
public static func recovery(
962
1000
email: String ,
963
- redirectTo: URL ?
1001
+ redirectTo: URL ? = nil
964
1002
) -> GenerateLinkParams {
965
1003
GenerateLinkParams (
966
- type: " recovery " ,
967
- email: email,
1004
+ body: . init(
1005
+ type: . recovery,
1006
+ email: email
1007
+ ) ,
968
1008
redirectTo: redirectTo
969
1009
)
970
1010
}
971
1011
972
1012
}
1013
+
1014
+ /// The response from the `generateLink` function.
1015
+ public struct GenerateLinkResponse : Hashable , Sendable {
1016
+ /// The properties related to the email link generated.
1017
+ public let properties : GenerateLinkProperties
1018
+ /// The user that the email link is associated to.
1019
+ public let user : User
1020
+ }
1021
+
1022
+ /// The properties related to the email link generated.
1023
+ public struct GenerateLinkProperties : Decodable , Hashable , Sendable {
1024
+ /// The email link to send to the users.
1025
+ /// The action link follows the following format: auth/v1/verify?type={verification_type}&token={hashed_token}&redirect_to={redirect_to}
1026
+ public let actionLink : URL
1027
+ /// The raw ramil OTP.
1028
+ /// You should send this in the email if you want your users to verify using an OTP instead of the action link.
1029
+ public let emailOTP : String
1030
+ /// The hashed token appended to the action link.
1031
+ public let hashedToken : String
1032
+ /// The URL appended to the action link.
1033
+ public let redirectTo : URL
1034
+ /// The verification type that the emaillink is associated to.
1035
+ public let verificationType : GenerateLinkType
1036
+
1037
+ enum CodingKeys : String , CodingKey {
1038
+ case actionLink = " action_link "
1039
+ case emailOTP = " email_otp "
1040
+ case hashedToken = " hashed_token "
1041
+ case redirectTo = " redirect_to "
1042
+ case verificationType = " verification_type "
1043
+ }
1044
+ }
1045
+
1046
+ public struct GenerateLinkType : RawRepresentable , Codable , Hashable , Sendable {
1047
+ public let rawValue : String
1048
+
1049
+ public init ( rawValue: String ) {
1050
+ self . rawValue = rawValue
1051
+ }
1052
+
1053
+ public static let signup = GenerateLinkType ( rawValue: " signup " )
1054
+ public static let invite = GenerateLinkType ( rawValue: " invite " )
1055
+ public static let magiclink = GenerateLinkType ( rawValue: " magiclink " )
1056
+ public static let recovery = GenerateLinkType ( rawValue: " recovery " )
1057
+ public static let emailChangeCurrent = GenerateLinkType ( rawValue: " email_change_current " )
1058
+ public static let emailChangeNew = GenerateLinkType ( rawValue: " email_change_new " )
1059
+ }
0 commit comments