@vvedantb/native-ui 0.31.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -6
- package/dist/auth/AccountScreens.jsx +450 -0
- package/dist/auth/AuthProviders.jsx +2 -2
- package/dist/auth/GoogleSignInButton.jsx +1 -1
- package/dist/auth/SignInScreen.jsx +28 -94
- package/dist/auth/authErrors.js +1 -1
- package/dist/auth/clerkCore3.js +110 -0
- package/dist/auth/index.js +2 -1
- package/dist/auth/totp.js +49 -60
- package/dist/entries/auth.js +1 -1
- package/package.json +4 -4
- package/src/auth/AccountScreens.tsx +294 -0
- package/src/auth/AuthProviders.tsx +8 -5
- package/src/auth/GoogleSignInButton.tsx +1 -1
- package/src/auth/SignInScreen.tsx +25 -55
- package/src/auth/authErrors.ts +1 -1
- package/src/auth/clerkCore3.ts +88 -0
- package/src/auth/index.ts +3 -1
- package/src/auth/totp.ts +5 -11
- package/src/entries/auth.ts +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import { useRef, useState } from "react";
|
|
3
3
|
import { Text, View } from "react-native";
|
|
4
|
-
import { useSignIn, useSignUp } from "@clerk/
|
|
4
|
+
import { useSignIn, useSignUp } from "@clerk/expo";
|
|
5
5
|
import { useRouter } from "expo-router";
|
|
6
6
|
import { Button } from "../Button";
|
|
7
7
|
import { textStyle } from "../controlStyles";
|
|
@@ -11,12 +11,10 @@ import { toast } from "../toastStore";
|
|
|
11
11
|
import { useScheme } from "../useScheme";
|
|
12
12
|
import { AuthScreen, FieldError, OrDivider } from "./AuthScreen";
|
|
13
13
|
import { authErrorMessage, DEFAULT_STAGE_TIMEOUT_MS, isAuthTimeoutError, logAuthFailure, withAuthTimeout } from "./authErrors";
|
|
14
|
+
import { clerkCall, signInCalls } from "./clerkCore3";
|
|
14
15
|
import { SecondFactorScreen } from "./SecondFactorScreen";
|
|
15
16
|
import { pickFirstFactorStrategy, pickSecondFactorStrategy, prepareFirstFactorIfNeeded, submitFirstFactor, supportedFirstFactorStrategies, supportedSecondFactorStrategies, useSecondFactor } from "./totp";
|
|
16
17
|
import { GoogleSignInButton } from "./GoogleSignInButton";
|
|
17
|
-
/** The first factor that emails a password-reset code. */
|
|
18
|
-
const RESET_STRATEGY = "reset_password_email_code";
|
|
19
|
-
|
|
20
18
|
/** The messages the screen can show. Generic: none names a provider. */
|
|
21
19
|
export const AUTH_MESSAGES = {
|
|
22
20
|
missingFields: "Enter your email and password",
|
|
@@ -137,8 +135,9 @@ export function SignInScreen({
|
|
|
137
135
|
onIncomplete,
|
|
138
136
|
stageTimeoutMs = DEFAULT_STAGE_TIMEOUT_MS
|
|
139
137
|
}) {
|
|
140
|
-
|
|
141
|
-
const
|
|
138
|
+
// Both are always defined: before Clerk loads, a call waits for it.
|
|
139
|
+
const signIn = signInCalls(useSignIn().signIn);
|
|
140
|
+
const signUpAttempt = useSignUp().signUp;
|
|
142
141
|
const router = useRouter();
|
|
143
142
|
const colorScheme = useScheme();
|
|
144
143
|
const [email, setEmail] = useState("");
|
|
@@ -205,10 +204,6 @@ export function SignInScreen({
|
|
|
205
204
|
await chooseStrategy(strategy_0, list_0);
|
|
206
205
|
};
|
|
207
206
|
const chooseFirstStrategy = async (strategy_1, list_1) => {
|
|
208
|
-
const {
|
|
209
|
-
signIn
|
|
210
|
-
} = signInState;
|
|
211
|
-
if (!signIn) return;
|
|
212
207
|
setFirstError("");
|
|
213
208
|
setFirstStrategy(strategy_1);
|
|
214
209
|
setPendingFirstFactor(true);
|
|
@@ -232,15 +227,10 @@ export function SignInScreen({
|
|
|
232
227
|
|
|
233
228
|
// Routes a sign-in attempt. `needs_first_factor` is built in only after `signIn.create`.
|
|
234
229
|
const routeAttempt = async (attempt_3, afterCreate) => {
|
|
235
|
-
const {
|
|
236
|
-
setActive
|
|
237
|
-
} = signInState;
|
|
238
230
|
// Clerk's `SignInStatus` omits `needs_client_trust`: widen before comparing.
|
|
239
231
|
const status = attempt_3.status;
|
|
240
|
-
if (status === "complete" && attempt_3.createdSessionId
|
|
241
|
-
await withAuthTimeout(setActive(
|
|
242
|
-
session: attempt_3.createdSessionId
|
|
243
|
-
}), "set-active", stageTimeoutMs);
|
|
232
|
+
if (status === "complete" && attempt_3.createdSessionId) {
|
|
233
|
+
await withAuthTimeout(signIn.setActive(), "set-active", stageTimeoutMs);
|
|
244
234
|
done();
|
|
245
235
|
} else if (status === "needs_new_password") {
|
|
246
236
|
setPendingFirstFactor(false);
|
|
@@ -257,15 +247,11 @@ export function SignInScreen({
|
|
|
257
247
|
}
|
|
258
248
|
};
|
|
259
249
|
const onFirstFactor = async firstCode => {
|
|
260
|
-
|
|
261
|
-
isLoaded,
|
|
262
|
-
signIn: signIn_0
|
|
263
|
-
} = signInState;
|
|
264
|
-
if (!isLoaded || !signIn_0 || firstLoading) return;
|
|
250
|
+
if (firstLoading) return;
|
|
265
251
|
setFirstLoading(true);
|
|
266
252
|
setFirstError("");
|
|
267
253
|
const result = await submitFirstFactor({
|
|
268
|
-
signIn
|
|
254
|
+
signIn,
|
|
269
255
|
code: firstCode,
|
|
270
256
|
strategy: firstStrategy,
|
|
271
257
|
timeoutMs: stageTimeoutMs
|
|
@@ -285,12 +271,7 @@ export function SignInScreen({
|
|
|
285
271
|
}
|
|
286
272
|
};
|
|
287
273
|
const onNewPassword = async () => {
|
|
288
|
-
|
|
289
|
-
isLoaded: isLoaded_0,
|
|
290
|
-
signIn: signIn_1,
|
|
291
|
-
setActive: setActive_0
|
|
292
|
-
} = signInState;
|
|
293
|
-
if (!isLoaded_0 || !signIn_1 || !setActive_0 || submitting) return;
|
|
274
|
+
if (submitting) return;
|
|
294
275
|
if (!newPassword) return fail(AUTH_MESSAGES.resetPasswordFailed, AUTH_MESSAGES.missingNewPassword);
|
|
295
276
|
if (minPasswordLength && newPassword.length < minPasswordLength) {
|
|
296
277
|
return fail(AUTH_MESSAGES.resetPasswordFailed, `Use at least ${minPasswordLength} characters for the password`);
|
|
@@ -301,15 +282,11 @@ export function SignInScreen({
|
|
|
301
282
|
setSubmitting(true);
|
|
302
283
|
setError("");
|
|
303
284
|
try {
|
|
304
|
-
const result_0 = await withAuthTimeout(
|
|
305
|
-
password: newPassword
|
|
306
|
-
}), "reset-password", stageTimeoutMs);
|
|
285
|
+
const result_0 = await withAuthTimeout(signIn.resetPassword(newPassword), "reset-password", stageTimeoutMs);
|
|
307
286
|
// Clerk's `SignInStatus` omits `needs_client_trust`: widen before comparing.
|
|
308
287
|
const afterReset = result_0.status;
|
|
309
288
|
if (afterReset === "complete" && result_0.createdSessionId) {
|
|
310
|
-
await withAuthTimeout(
|
|
311
|
-
session: result_0.createdSessionId
|
|
312
|
-
}), "set-active", stageTimeoutMs);
|
|
289
|
+
await withAuthTimeout(signIn.setActive(), "set-active", stageTimeoutMs);
|
|
313
290
|
done();
|
|
314
291
|
} else if (afterReset === "needs_second_factor" || afterReset === "needs_client_trust") {
|
|
315
292
|
// A reset on an account with two-step verification: the code step, then the session.
|
|
@@ -329,20 +306,12 @@ export function SignInScreen({
|
|
|
329
306
|
}
|
|
330
307
|
};
|
|
331
308
|
const onSignIn = async () => {
|
|
332
|
-
|
|
333
|
-
isLoaded: isLoaded_1,
|
|
334
|
-
signIn: signIn_2,
|
|
335
|
-
setActive: setActive_1
|
|
336
|
-
} = signInState;
|
|
337
|
-
if (!isLoaded_1 || !signIn_2 || !setActive_1 || submitting) return;
|
|
309
|
+
if (submitting) return;
|
|
338
310
|
if (!email || !password) return fail(AUTH_MESSAGES.signInFailed, AUTH_MESSAGES.missingFields);
|
|
339
311
|
setSubmitting(true);
|
|
340
312
|
setError("");
|
|
341
313
|
try {
|
|
342
|
-
const attempt_4 = await withAuthTimeout(
|
|
343
|
-
identifier: email,
|
|
344
|
-
password
|
|
345
|
-
}), "create", stageTimeoutMs);
|
|
314
|
+
const attempt_4 = await withAuthTimeout(signIn.password(email, password), "create", stageTimeoutMs);
|
|
346
315
|
await routeAttempt(attempt_4, true);
|
|
347
316
|
} catch (caught_1) {
|
|
348
317
|
logAuthFailure("create", caught_1);
|
|
@@ -356,21 +325,10 @@ export function SignInScreen({
|
|
|
356
325
|
|
|
357
326
|
// Emails the reset code. Throws what the call throws.
|
|
358
327
|
const requestResetCode = async () => {
|
|
359
|
-
|
|
360
|
-
signIn: signIn_3
|
|
361
|
-
} = signInState;
|
|
362
|
-
if (!signIn_3) return;
|
|
363
|
-
await withAuthTimeout(signIn_3.create({
|
|
364
|
-
strategy: RESET_STRATEGY,
|
|
365
|
-
identifier: email.trim()
|
|
366
|
-
}), "create", stageTimeoutMs);
|
|
328
|
+
await withAuthTimeout(signIn.sendResetCode(email.trim()), "create", stageTimeoutMs);
|
|
367
329
|
};
|
|
368
330
|
const onResetRequest = async () => {
|
|
369
|
-
|
|
370
|
-
isLoaded: isLoaded_2,
|
|
371
|
-
signIn: signIn_4
|
|
372
|
-
} = signInState;
|
|
373
|
-
if (!isLoaded_2 || !signIn_4 || submitting) return;
|
|
331
|
+
if (submitting) return;
|
|
374
332
|
if (!email.trim()) return fail(AUTH_MESSAGES.sendResetFailed, AUTH_MESSAGES.missingEmail);
|
|
375
333
|
setSubmitting(true);
|
|
376
334
|
setError("");
|
|
@@ -386,11 +344,7 @@ export function SignInScreen({
|
|
|
386
344
|
}
|
|
387
345
|
};
|
|
388
346
|
const onResetResend = async () => {
|
|
389
|
-
|
|
390
|
-
isLoaded: isLoaded_3,
|
|
391
|
-
signIn: signIn_5
|
|
392
|
-
} = signInState;
|
|
393
|
-
if (!isLoaded_3 || !signIn_5 || resetLoading) return;
|
|
347
|
+
if (resetLoading) return;
|
|
394
348
|
setResetLoading(true);
|
|
395
349
|
setResetCodeError("");
|
|
396
350
|
try {
|
|
@@ -405,18 +359,11 @@ export function SignInScreen({
|
|
|
405
359
|
|
|
406
360
|
// Checks the emailed code. A good code gives `needs_new_password`, which `routeAttempt` shows.
|
|
407
361
|
const onResetCode = async resetCode => {
|
|
408
|
-
|
|
409
|
-
isLoaded: isLoaded_4,
|
|
410
|
-
signIn: signIn_6
|
|
411
|
-
} = signInState;
|
|
412
|
-
if (!isLoaded_4 || !signIn_6 || resetLoading) return;
|
|
362
|
+
if (resetLoading) return;
|
|
413
363
|
setResetLoading(true);
|
|
414
364
|
setResetCodeError("");
|
|
415
365
|
try {
|
|
416
|
-
const attempt_5 = await withAuthTimeout(
|
|
417
|
-
strategy: RESET_STRATEGY,
|
|
418
|
-
code: resetCode
|
|
419
|
-
}), "attempt-first-factor", stageTimeoutMs);
|
|
366
|
+
const attempt_5 = await withAuthTimeout(signIn.verifyResetCode(resetCode), "attempt-first-factor", stageTimeoutMs);
|
|
420
367
|
const status_0 = attempt_5.status;
|
|
421
368
|
const known = ["complete", "needs_new_password", "needs_second_factor", "needs_client_trust"];
|
|
422
369
|
if (status_0 && known.includes(status_0)) {
|
|
@@ -453,11 +400,7 @@ export function SignInScreen({
|
|
|
453
400
|
secondFactor.clearError();
|
|
454
401
|
};
|
|
455
402
|
const onSignUp = async () => {
|
|
456
|
-
|
|
457
|
-
isLoaded: isLoaded_5,
|
|
458
|
-
signUp: attempt_6
|
|
459
|
-
} = signUpState;
|
|
460
|
-
if (!isLoaded_5 || !attempt_6 || submitting) return;
|
|
403
|
+
if (submitting) return;
|
|
461
404
|
if (!email || !password) return fail(AUTH_MESSAGES.signUpFailed, AUTH_MESSAGES.missingFields);
|
|
462
405
|
if (minPasswordLength && password.length < minPasswordLength) {
|
|
463
406
|
return fail(AUTH_MESSAGES.signUpFailed, `Use at least ${minPasswordLength} characters for the password`);
|
|
@@ -471,13 +414,11 @@ export function SignInScreen({
|
|
|
471
414
|
setSubmitting(true);
|
|
472
415
|
setError("");
|
|
473
416
|
try {
|
|
474
|
-
await
|
|
417
|
+
await clerkCall(signUpAttempt.password({
|
|
475
418
|
emailAddress: email,
|
|
476
419
|
password
|
|
477
|
-
});
|
|
478
|
-
await
|
|
479
|
-
strategy: "email_code"
|
|
480
|
-
});
|
|
420
|
+
}));
|
|
421
|
+
await clerkCall(signUpAttempt.verifications.sendEmailCode());
|
|
481
422
|
setPendingVerification(true);
|
|
482
423
|
} catch (caught_5) {
|
|
483
424
|
fail(AUTH_MESSAGES.signUpFailed, authErrorMessage(caught_5, AUTH_MESSAGES.signUpFailed));
|
|
@@ -486,23 +427,16 @@ export function SignInScreen({
|
|
|
486
427
|
}
|
|
487
428
|
};
|
|
488
429
|
const onVerify = async () => {
|
|
489
|
-
|
|
490
|
-
isLoaded: isLoaded_6,
|
|
491
|
-
signUp: attempt_7,
|
|
492
|
-
setActive: setActive_2
|
|
493
|
-
} = signUpState;
|
|
494
|
-
if (!isLoaded_6 || !attempt_7 || !setActive_2 || submitting) return;
|
|
430
|
+
if (submitting) return;
|
|
495
431
|
if (!code) return fail(AUTH_MESSAGES.verifyFailed, AUTH_MESSAGES.missingCode);
|
|
496
432
|
setSubmitting(true);
|
|
497
433
|
setError("");
|
|
498
434
|
try {
|
|
499
|
-
|
|
435
|
+
await clerkCall(signUpAttempt.verifications.verifyEmailCode({
|
|
500
436
|
code
|
|
501
|
-
});
|
|
502
|
-
if (
|
|
503
|
-
await
|
|
504
|
-
session: result_2.createdSessionId
|
|
505
|
-
});
|
|
437
|
+
}));
|
|
438
|
+
if (signUpAttempt.status === "complete" && signUpAttempt.createdSessionId) {
|
|
439
|
+
await clerkCall(signUpAttempt.finalize());
|
|
506
440
|
done();
|
|
507
441
|
} else {
|
|
508
442
|
fail(AUTH_MESSAGES.verifyFailed, AUTH_MESSAGES.needsAnotherStep);
|
package/dist/auth/authErrors.js
CHANGED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** The sign-in resource of the `useSignIn` hook at the root of `@clerk/expo` 4. */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Awaits a call on Clerk's sign-in or sign-up resource. These calls resolve
|
|
5
|
+
* with `{ error }` where the older ones rejected: this throws that error, so
|
|
6
|
+
* `authErrorMessage` and `logAuthFailure` read it as before.
|
|
7
|
+
*/
|
|
8
|
+
export async function clerkCall(call) {
|
|
9
|
+
const {
|
|
10
|
+
error
|
|
11
|
+
} = await call;
|
|
12
|
+
if (error) throw error;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Wraps the sign-in resource for the helpers in `totp.ts` and for
|
|
17
|
+
* `SignInScreen`. Each method makes the call, throws its error, and returns
|
|
18
|
+
* the sign-in as it stands after the call. The methods are `async`, so an
|
|
19
|
+
* error the resource throws at once is also a rejection.
|
|
20
|
+
*/
|
|
21
|
+
export function signInCalls(signIn) {
|
|
22
|
+
const state = () => ({
|
|
23
|
+
status: signIn.status,
|
|
24
|
+
createdSessionId: signIn.createdSessionId,
|
|
25
|
+
supportedFirstFactors: signIn.supportedFirstFactors,
|
|
26
|
+
supportedSecondFactors: signIn.supportedSecondFactors
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
get supportedFirstFactors() {
|
|
30
|
+
return signIn.supportedFirstFactors;
|
|
31
|
+
},
|
|
32
|
+
get supportedSecondFactors() {
|
|
33
|
+
return signIn.supportedSecondFactors;
|
|
34
|
+
},
|
|
35
|
+
/** Starts a new sign-in with email and password. */
|
|
36
|
+
async password(identifier, password) {
|
|
37
|
+
await clerkCall(signIn.password({
|
|
38
|
+
identifier,
|
|
39
|
+
password
|
|
40
|
+
}));
|
|
41
|
+
return state();
|
|
42
|
+
},
|
|
43
|
+
/** Starts a new sign-in for `identifier` and emails its password-reset code. */
|
|
44
|
+
async sendResetCode(identifier) {
|
|
45
|
+
await clerkCall(signIn.create({
|
|
46
|
+
identifier
|
|
47
|
+
}));
|
|
48
|
+
await clerkCall(signIn.resetPasswordEmailCode.sendCode());
|
|
49
|
+
},
|
|
50
|
+
async verifyResetCode(code) {
|
|
51
|
+
await clerkCall(signIn.resetPasswordEmailCode.verifyCode({
|
|
52
|
+
code
|
|
53
|
+
}));
|
|
54
|
+
return state();
|
|
55
|
+
},
|
|
56
|
+
/** Sets the new password. Other sessions stay signed in, as before. */
|
|
57
|
+
async resetPassword(password) {
|
|
58
|
+
await clerkCall(signIn.resetPasswordEmailCode.submitPassword({
|
|
59
|
+
password,
|
|
60
|
+
signOutOfOtherSessions: false
|
|
61
|
+
}));
|
|
62
|
+
return state();
|
|
63
|
+
},
|
|
64
|
+
async prepareFirstFactor(params) {
|
|
65
|
+
if (params.strategy === "phone_code") {
|
|
66
|
+
await clerkCall(signIn.phoneCode.sendCode({
|
|
67
|
+
phoneNumberId: params.phoneNumberId
|
|
68
|
+
}));
|
|
69
|
+
} else {
|
|
70
|
+
await clerkCall(signIn.emailCode.sendCode({
|
|
71
|
+
emailAddressId: params.emailAddressId
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
async attemptFirstFactor(params) {
|
|
76
|
+
const {
|
|
77
|
+
code
|
|
78
|
+
} = params;
|
|
79
|
+
if (params.strategy === "phone_code") await clerkCall(signIn.phoneCode.verifyCode({
|
|
80
|
+
code
|
|
81
|
+
}));else await clerkCall(signIn.emailCode.verifyCode({
|
|
82
|
+
code
|
|
83
|
+
}));
|
|
84
|
+
return state();
|
|
85
|
+
},
|
|
86
|
+
/** Sends the second-factor code. Clerk picks the phone number or email of the sign-in itself. */
|
|
87
|
+
async prepareSecondFactor(params) {
|
|
88
|
+
if (params.strategy === "phone_code") await clerkCall(signIn.mfa.sendPhoneCode());else await clerkCall(signIn.mfa.sendEmailCode());
|
|
89
|
+
},
|
|
90
|
+
async attemptSecondFactor(params) {
|
|
91
|
+
const {
|
|
92
|
+
code
|
|
93
|
+
} = params;
|
|
94
|
+
if (params.strategy === "totp") await clerkCall(signIn.mfa.verifyTOTP({
|
|
95
|
+
code
|
|
96
|
+
}));else if (params.strategy === "backup_code") await clerkCall(signIn.mfa.verifyBackupCode({
|
|
97
|
+
code
|
|
98
|
+
}));else if (params.strategy === "phone_code") await clerkCall(signIn.mfa.verifyPhoneCode({
|
|
99
|
+
code
|
|
100
|
+
}));else await clerkCall(signIn.mfa.verifyEmailCode({
|
|
101
|
+
code
|
|
102
|
+
}));
|
|
103
|
+
return state();
|
|
104
|
+
},
|
|
105
|
+
/** Makes the session of a complete sign-in the active one. */
|
|
106
|
+
async setActive() {
|
|
107
|
+
await clerkCall(signIn.finalize());
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
package/dist/auth/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Clerk + Convex providers and the shared sign-in and sign-up screens. On
|
|
2
|
-
// `@vvedantb/native-ui/auth` only: they import `@clerk/
|
|
2
|
+
// `@vvedantb/native-ui/auth` only: they import `@clerk/expo`, `convex`,
|
|
3
3
|
// `expo-auth-session`, `expo-web-browser` and `expo-router`, and Metro does not
|
|
4
4
|
// tree-shake.
|
|
5
5
|
export { AuthProviders } from "./AuthProviders";
|
|
@@ -7,5 +7,6 @@ export { AuthScreen, OrDivider, FieldError } from "./AuthScreen";
|
|
|
7
7
|
export { authErrorMessage, logAuthFailure, withAuthTimeout, AuthTimeoutError, isAuthTimeoutError, AUTH_TIMEOUT_CODE, DEFAULT_STAGE_TIMEOUT_MS, CREDENTIAL_ERROR_CODES } from "./authErrors";
|
|
8
8
|
export { GoogleSignInButton, useGoogleSignIn, useWarmUpBrowser, GOOGLE_ERROR_MESSAGE } from "./GoogleSignInButton";
|
|
9
9
|
export { SignInScreen, SignUpScreen, ResetPasswordScreen, AUTH_MESSAGES } from "./SignInScreen";
|
|
10
|
+
export { ChangePasswordScreen, DeleteAccountScreen, ACCOUNT_MESSAGES } from "./AccountScreens";
|
|
10
11
|
export { SecondFactorScreen } from "./SecondFactorScreen";
|
|
11
12
|
export { submitTotpSecondFactor, submitSecondFactor, prepareSecondFactorIfNeeded, prepareFirstFactorIfNeeded, submitFirstFactor, pickFirstFactorStrategy, supportedFirstFactorStrategies, FIRST_FACTOR_PREFERENCE, pickSecondFactorStrategy, supportedSecondFactorStrategies, SECOND_FACTOR_PREFERENCE, useSecondFactor, TOTP_MESSAGES } from "./totp";
|
package/dist/auth/totp.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import { useState } from "react";
|
|
3
|
-
import { useSignIn } from "@clerk/
|
|
3
|
+
import { useSignIn } from "@clerk/expo";
|
|
4
4
|
import { authErrorMessage, DEFAULT_STAGE_TIMEOUT_MS, isAuthTimeoutError, logAuthFailure, withAuthTimeout } from "./authErrors";
|
|
5
|
+
import { signInCalls } from "./clerkCore3";
|
|
5
6
|
|
|
6
7
|
/** Logs a timed-out stage. Other failures are not logged here. */
|
|
7
8
|
const logTimeout = (stage, error) => {
|
|
@@ -250,7 +251,7 @@ export function submitTotpSecondFactor(args) {
|
|
|
250
251
|
* `{ ok: true }` the session is active: navigate in the caller.
|
|
251
252
|
*/
|
|
252
253
|
export function useSecondFactor(t0) {
|
|
253
|
-
const $ = _c(
|
|
254
|
+
const $ = _c(21);
|
|
254
255
|
let t1;
|
|
255
256
|
if ($[0] !== t0) {
|
|
256
257
|
t1 = t0 === undefined ? {} : t0;
|
|
@@ -260,37 +261,35 @@ export function useSecondFactor(t0) {
|
|
|
260
261
|
t1 = $[1];
|
|
261
262
|
}
|
|
262
263
|
const options = t1;
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
264
|
+
const t2 = useSignIn();
|
|
265
|
+
let t3;
|
|
266
|
+
if ($[2] !== t2.signIn) {
|
|
267
|
+
t3 = signInCalls(t2.signIn);
|
|
268
|
+
$[2] = t2.signIn;
|
|
269
|
+
$[3] = t3;
|
|
270
|
+
} else {
|
|
271
|
+
t3 = $[3];
|
|
272
|
+
}
|
|
273
|
+
const signIn = t3;
|
|
268
274
|
const [chosen, setChosen] = useState(null);
|
|
269
275
|
const strategy = chosen ?? options.strategy ?? "totp";
|
|
270
276
|
const [loading, setLoading] = useState(false);
|
|
271
277
|
const [error, setError] = useState("");
|
|
272
278
|
const timeoutMs = options.stageTimeoutMs ?? DEFAULT_STAGE_TIMEOUT_MS;
|
|
273
|
-
let
|
|
274
|
-
if ($[
|
|
275
|
-
|
|
279
|
+
let t4;
|
|
280
|
+
if ($[4] !== error || $[5] !== loading || $[6] !== signIn || $[7] !== strategy || $[8] !== timeoutMs) {
|
|
281
|
+
t4 = async code => {
|
|
276
282
|
if (loading) {
|
|
277
283
|
return {
|
|
278
284
|
ok: false,
|
|
279
285
|
error
|
|
280
286
|
};
|
|
281
287
|
}
|
|
282
|
-
if (!isLoaded || !signIn || !setActive) {
|
|
283
|
-
setError(TOTP_MESSAGES.notReady);
|
|
284
|
-
return {
|
|
285
|
-
ok: false,
|
|
286
|
-
error: TOTP_MESSAGES.notReady
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
288
|
setLoading(true);
|
|
290
289
|
setError("");
|
|
291
290
|
const result = await submitSecondFactor({
|
|
292
291
|
signIn,
|
|
293
|
-
setActive,
|
|
292
|
+
setActive: signIn.setActive,
|
|
294
293
|
code,
|
|
295
294
|
strategy,
|
|
296
295
|
timeoutMs
|
|
@@ -301,29 +300,20 @@ export function useSecondFactor(t0) {
|
|
|
301
300
|
setLoading(false);
|
|
302
301
|
return result;
|
|
303
302
|
};
|
|
304
|
-
$[
|
|
305
|
-
$[
|
|
306
|
-
$[4] = loading;
|
|
307
|
-
$[5] = setActive;
|
|
303
|
+
$[4] = error;
|
|
304
|
+
$[5] = loading;
|
|
308
305
|
$[6] = signIn;
|
|
309
306
|
$[7] = strategy;
|
|
310
307
|
$[8] = timeoutMs;
|
|
311
|
-
$[9] =
|
|
308
|
+
$[9] = t4;
|
|
312
309
|
} else {
|
|
313
|
-
|
|
310
|
+
t4 = $[9];
|
|
314
311
|
}
|
|
315
|
-
const submit =
|
|
316
|
-
let
|
|
317
|
-
if ($[10] !==
|
|
318
|
-
|
|
319
|
-
const prepareStrategy =
|
|
320
|
-
if (!isLoaded || !signIn) {
|
|
321
|
-
setError(TOTP_MESSAGES.notReady);
|
|
322
|
-
return {
|
|
323
|
-
ok: false,
|
|
324
|
-
error: TOTP_MESSAGES.notReady
|
|
325
|
-
};
|
|
326
|
-
}
|
|
312
|
+
const submit = t4;
|
|
313
|
+
let t5;
|
|
314
|
+
if ($[10] !== signIn || $[11] !== strategy || $[12] !== timeoutMs) {
|
|
315
|
+
t5 = async (t6, factor) => {
|
|
316
|
+
const prepareStrategy = t6 === undefined ? strategy : t6;
|
|
327
317
|
setLoading(true);
|
|
328
318
|
setError("");
|
|
329
319
|
const result_0 = await prepareSecondFactorIfNeeded({
|
|
@@ -338,41 +328,40 @@ export function useSecondFactor(t0) {
|
|
|
338
328
|
setLoading(false);
|
|
339
329
|
return result_0;
|
|
340
330
|
};
|
|
341
|
-
$[10] =
|
|
342
|
-
$[11] =
|
|
343
|
-
$[12] =
|
|
344
|
-
$[13] =
|
|
345
|
-
$[14] = t3;
|
|
331
|
+
$[10] = signIn;
|
|
332
|
+
$[11] = strategy;
|
|
333
|
+
$[12] = timeoutMs;
|
|
334
|
+
$[13] = t5;
|
|
346
335
|
} else {
|
|
347
|
-
|
|
336
|
+
t5 = $[13];
|
|
348
337
|
}
|
|
349
|
-
const prepare =
|
|
350
|
-
let
|
|
351
|
-
if ($[
|
|
352
|
-
|
|
353
|
-
$[
|
|
338
|
+
const prepare = t5;
|
|
339
|
+
let t6;
|
|
340
|
+
if ($[14] === Symbol.for("react.memo_cache_sentinel")) {
|
|
341
|
+
t6 = () => setError("");
|
|
342
|
+
$[14] = t6;
|
|
354
343
|
} else {
|
|
355
|
-
|
|
344
|
+
t6 = $[14];
|
|
356
345
|
}
|
|
357
|
-
let
|
|
358
|
-
if ($[
|
|
359
|
-
|
|
346
|
+
let t7;
|
|
347
|
+
if ($[15] !== error || $[16] !== loading || $[17] !== prepare || $[18] !== strategy || $[19] !== submit) {
|
|
348
|
+
t7 = {
|
|
360
349
|
submit,
|
|
361
350
|
prepare,
|
|
362
351
|
strategy,
|
|
363
352
|
setStrategy: setChosen,
|
|
364
353
|
loading,
|
|
365
354
|
error,
|
|
366
|
-
clearError:
|
|
355
|
+
clearError: t6
|
|
367
356
|
};
|
|
368
|
-
$[
|
|
369
|
-
$[
|
|
370
|
-
$[
|
|
371
|
-
$[
|
|
372
|
-
$[
|
|
373
|
-
$[
|
|
357
|
+
$[15] = error;
|
|
358
|
+
$[16] = loading;
|
|
359
|
+
$[17] = prepare;
|
|
360
|
+
$[18] = strategy;
|
|
361
|
+
$[19] = submit;
|
|
362
|
+
$[20] = t7;
|
|
374
363
|
} else {
|
|
375
|
-
|
|
364
|
+
t7 = $[20];
|
|
376
365
|
}
|
|
377
|
-
return
|
|
366
|
+
return t7;
|
|
378
367
|
}
|
package/dist/entries/auth.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// `@vvedantb/native-ui/auth`: `AuthProviders`, `SignInScreen`, `SignUpScreen`,
|
|
2
2
|
// `GoogleSignInButton` and the auth frame. Not on the root entry: it imports
|
|
3
|
-
// `@clerk/
|
|
3
|
+
// `@clerk/expo`, `convex`, `expo-auth-session`, `expo-web-browser` and
|
|
4
4
|
// `expo-router`, and Metro does not tree-shake.
|
|
5
5
|
export * from "../auth";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/native-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared React Native / Expo UI primitives. Floating surfaces, forms, overlays, toasts, settings chrome, tab bar, AI chat parts, the family app marks, a NativeWind preset, the Expo web root and Clerk + Convex auth screens.",
|
|
6
6
|
"type": "module",
|
|
@@ -190,7 +190,7 @@
|
|
|
190
190
|
"sideEffects": false,
|
|
191
191
|
"peerDependencies": {
|
|
192
192
|
"expo-paste-input": ">=0.2.0",
|
|
193
|
-
"@clerk/
|
|
193
|
+
"@clerk/expo": ">=4.16.0",
|
|
194
194
|
"@expo/vector-icons": "*",
|
|
195
195
|
"@json-render/core": ">=0.21.0",
|
|
196
196
|
"@json-render/react-native": ">=0.21.0",
|
|
@@ -234,7 +234,7 @@
|
|
|
234
234
|
"expo-paste-input": {
|
|
235
235
|
"optional": true
|
|
236
236
|
},
|
|
237
|
-
"@clerk/
|
|
237
|
+
"@clerk/expo": {
|
|
238
238
|
"optional": true
|
|
239
239
|
},
|
|
240
240
|
"@swmansion/react-native-bottom-sheet": {
|
|
@@ -308,7 +308,7 @@
|
|
|
308
308
|
}
|
|
309
309
|
},
|
|
310
310
|
"devDependencies": {
|
|
311
|
-
"@clerk/
|
|
311
|
+
"@clerk/expo": "4.17.2",
|
|
312
312
|
"@types/react": "^19.1.0",
|
|
313
313
|
"react": "^19.1.0",
|
|
314
314
|
"typescript": "^5.9.0",
|