@@ -46,6 +46,7 @@ class Auth {
46
46
required Persistor persistor,
47
47
bool sendTelemetryData = true ,
48
48
HttpService httpService = const DefaultHttpService (),
49
+ ClerkLocalesLookup localesLookup = defaultLocalesList,
49
50
SessionTokenPollMode pollMode = SessionTokenPollMode .lazy,
50
51
}) : telemetry = Telemetry (
51
52
publishableKey: publishableKey,
@@ -57,9 +58,13 @@ class Auth {
57
58
publishableKey: publishableKey,
58
59
persistor: persistor,
59
60
httpService: httpService,
61
+ localesLookup: localesLookup,
60
62
pollMode: pollMode,
61
63
);
62
64
65
+ /// Use 'English' as the default locale
66
+ static List <String > defaultLocalesList () => < String > ['en' ];
67
+
63
68
/// The service to send telemetry to the back end
64
69
final Telemetry telemetry;
65
70
@@ -151,10 +156,14 @@ class Auth {
151
156
}
152
157
153
158
ApiResponse _housekeeping (ApiResponse resp) {
154
- if (resp.client case Client client when resp.isOkay) {
159
+ if (resp.isError) {
160
+ throw AuthError (
161
+ code: AuthErrorCode .serverErrorResponse,
162
+ message: '{arg}: ${resp .errorMessage }' ,
163
+ argument: resp.status.toString (),
164
+ );
165
+ } else if (resp.client case Client client) {
155
166
this .client = client;
156
- } else {
157
- throw AuthError (code: resp.status, message: resp.errorMessage);
158
167
}
159
168
return resp;
160
169
}
@@ -185,7 +194,10 @@ class Auth {
185
194
: null ;
186
195
final token = await _api.sessionToken (org, templateName);
187
196
if (token is ! SessionToken ) {
188
- throw AuthError (message: 'No session token retrieved' );
197
+ throw const AuthError (
198
+ message: 'No session token retrieved' ,
199
+ code: AuthErrorCode .noSessionTokenRetrieved,
200
+ );
189
201
}
190
202
return token;
191
203
}
@@ -339,7 +351,10 @@ class Auth {
339
351
String ? signature,
340
352
}) async {
341
353
if (password != passwordConfirmation) {
342
- throw AuthError (message: "Password and password confirmation must match" );
354
+ throw const AuthError (
355
+ message: "Password and password confirmation must match" ,
356
+ code: AuthErrorCode .passwordMatchError,
357
+ );
343
358
}
344
359
345
360
switch (client.signUp) {
@@ -534,8 +549,9 @@ class Auth {
534
549
535
550
final expiry = client.signIn? .firstFactorVerification? .expireAt;
536
551
if (expiry? .isAfter (DateTime .timestamp ()) != true ) {
537
- throw AuthError (
552
+ throw const AuthError (
538
553
message: 'Awaited user action not completed in required timeframe' ,
554
+ code: AuthErrorCode .actionNotTimely,
539
555
);
540
556
}
541
557
0 commit comments