This repository has been archived by the owner on May 13, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
auth_response.dart
92 lines (74 loc) · 2.52 KB
/
auth_response.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import 'package:gotrue/gotrue.dart';
import 'package:gotrue/src/constants.dart';
/// Response which might or might not contain session and/or user
class AuthResponse {
final Session? session;
final User? user;
AuthResponse({
this.session,
User? user,
}) : user = user ?? session?.user;
/// Instanciates an `AuthResponse` object from json response.
AuthResponse.fromJson(Map<String, dynamic> json)
: session = Session.fromJson(json),
user = User.fromJson(json) ?? Session.fromJson(json)?.user;
}
/// Response of OAuth signin
class OAuthResponse {
final Provider provider;
final String? url;
/// Instanciates an `OAuthResponse` object from json response.
const OAuthResponse({
required this.provider,
this.url,
});
}
/// Response that contains a user
class UserResponse {
final User? user;
UserResponse.fromJson(Map<String, dynamic> json) : user = User.fromJson(json);
}
class AuthSessionUrlResponse {
final Session session;
final String? redirectType;
const AuthSessionUrlResponse({
required this.session,
required this.redirectType,
});
}
class GenerateLinkResponse {
final GenerateLinkProperties properties;
final User user;
GenerateLinkResponse.fromJson(Map<String, dynamic> json)
: properties = GenerateLinkProperties.fromJson(json),
user = User.fromJson(json)!;
}
class GenerateLinkProperties {
/// The email link to send to the user.
/// The action_link follows the following format: auth/v1/verify?type={verification_type}&token={hashed_token}&redirect_to={redirect_to}
final String actionLink;
/// The raw email OTP.
/// You should send this in the email if you want your users to verify using an OTP instead of the action link.
final String emailOtp;
/// The hashed token appended to the action link.
final String hashedToken;
/// The URL appended to the action link.
final String redirectTo;
/// The verification type that the email link is associated to.
final GenerateLinkType verificationType;
GenerateLinkProperties.fromJson(Map<String, dynamic> json)
: actionLink = json['action_link'],
emailOtp = json['email_otp'],
hashedToken = json['hashed_token'],
redirectTo = json['redirect_to'],
verificationType =
GenerateLinkTypeExtended.fromString(json['verification_type']);
}
extension ToSnakeCase on Enum {
String get snakeCase {
RegExp exp = RegExp(r'(?<=[a-z])[A-Z]');
return name
.replaceAllMapped(exp, (Match m) => ('_${m.group(0)}'))
.toLowerCase();
}
}