@vvedantb/native-ui 0.32.0 → 0.34.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/dist/UpdateChecker.jsx +80 -61
- package/dist/auth/SignInScreen.jsx +28 -94
- package/dist/auth/clerkCore3.js +110 -0
- package/dist/auth/totp.js +49 -60
- package/dist/index.js +1 -1
- package/dist/updateCheck.js +32 -0
- package/package.json +2 -2
- package/src/UpdateChecker.tsx +30 -9
- package/src/auth/SignInScreen.tsx +25 -55
- package/src/auth/clerkCore3.ts +88 -0
- package/src/auth/totp.ts +5 -11
- package/src/index.ts +2 -2
- package/src/updateCheck.ts +45 -0
package/dist/UpdateChecker.jsx
CHANGED
|
@@ -2,7 +2,7 @@ import { c as _c } from "react/compiler-runtime";
|
|
|
2
2
|
import { useEffect, useRef, useState } from "react";
|
|
3
3
|
import { Linking } from "react-native";
|
|
4
4
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "./AlertDialog";
|
|
5
|
-
import { fetchGitHubUpdate } from "./updateCheck";
|
|
5
|
+
import { fetchGitHubUpdate, fetchVStoreUpdate } from "./updateCheck";
|
|
6
6
|
|
|
7
7
|
/** Opens the Updates tab of V Store, the Project V Android app store. */
|
|
8
8
|
export const V_STORE_UPDATES_URL = "vstore://updates";
|
|
@@ -221,7 +221,8 @@ async function readDismissed(storage, key) {
|
|
|
221
221
|
* Looks for a newer version once when it mounts and offers it in an
|
|
222
222
|
* `UpdatePrompt`. Mount it once, near the app root.
|
|
223
223
|
*
|
|
224
|
-
* - The check reads the GitHub releases of `source`,
|
|
224
|
+
* - The check reads the GitHub releases of `source`, asks V Store (`vStore`),
|
|
225
|
+
* or calls `check`.
|
|
225
226
|
* Offline, rate limited, a failed check or no `currentVersion`: nothing is
|
|
226
227
|
* offered, and nothing is shown.
|
|
227
228
|
* - Later (and Android back) hides that version until a newer one is out,
|
|
@@ -230,7 +231,7 @@ async function readDismissed(storage, key) {
|
|
|
230
231
|
* so it asks again at the next start if the update was not installed.
|
|
231
232
|
*/
|
|
232
233
|
export function UpdateChecker(t0) {
|
|
233
|
-
const $ = _c(
|
|
234
|
+
const $ = _c(50);
|
|
234
235
|
let check;
|
|
235
236
|
let currentVersion;
|
|
236
237
|
let onDownload;
|
|
@@ -241,10 +242,12 @@ export function UpdateChecker(t0) {
|
|
|
241
242
|
let storage;
|
|
242
243
|
let t1;
|
|
243
244
|
let t2;
|
|
245
|
+
let vStore;
|
|
244
246
|
if ($[0] !== t0) {
|
|
245
247
|
({
|
|
246
248
|
currentVersion,
|
|
247
249
|
source,
|
|
250
|
+
vStore,
|
|
248
251
|
check,
|
|
249
252
|
enabled: t1,
|
|
250
253
|
storage,
|
|
@@ -265,6 +268,7 @@ export function UpdateChecker(t0) {
|
|
|
265
268
|
$[8] = storage;
|
|
266
269
|
$[9] = t1;
|
|
267
270
|
$[10] = t2;
|
|
271
|
+
$[11] = vStore;
|
|
268
272
|
} else {
|
|
269
273
|
check = $[1];
|
|
270
274
|
currentVersion = $[2];
|
|
@@ -276,47 +280,55 @@ export function UpdateChecker(t0) {
|
|
|
276
280
|
storage = $[8];
|
|
277
281
|
t1 = $[9];
|
|
278
282
|
t2 = $[10];
|
|
283
|
+
vStore = $[11];
|
|
279
284
|
}
|
|
280
285
|
const enabled = t1 === undefined ? true : t1;
|
|
281
286
|
const storageKey = t2 === undefined ? "updateDismissed" : t2;
|
|
282
287
|
const [update, setUpdate] = useState(null);
|
|
283
288
|
let t3;
|
|
284
|
-
if ($[
|
|
289
|
+
if ($[12] !== check || $[13] !== storage || $[14] !== storageKey || $[15] !== vStore) {
|
|
285
290
|
t3 = {
|
|
286
291
|
check,
|
|
292
|
+
vStore,
|
|
287
293
|
storage,
|
|
288
294
|
storageKey
|
|
289
295
|
};
|
|
290
|
-
$[
|
|
291
|
-
$[
|
|
292
|
-
$[
|
|
293
|
-
$[
|
|
296
|
+
$[12] = check;
|
|
297
|
+
$[13] = storage;
|
|
298
|
+
$[14] = storageKey;
|
|
299
|
+
$[15] = vStore;
|
|
300
|
+
$[16] = t3;
|
|
294
301
|
} else {
|
|
295
|
-
t3 = $[
|
|
302
|
+
t3 = $[16];
|
|
296
303
|
}
|
|
297
304
|
const latest = useRef(t3);
|
|
298
305
|
let t4;
|
|
299
|
-
if ($[
|
|
306
|
+
if ($[17] !== check || $[18] !== storage || $[19] !== storageKey || $[20] !== vStore) {
|
|
300
307
|
t4 = () => {
|
|
301
308
|
latest.current = {
|
|
302
309
|
check,
|
|
310
|
+
vStore,
|
|
303
311
|
storage,
|
|
304
312
|
storageKey
|
|
305
313
|
};
|
|
306
314
|
};
|
|
307
|
-
$[
|
|
308
|
-
$[
|
|
309
|
-
$[
|
|
310
|
-
$[
|
|
315
|
+
$[17] = check;
|
|
316
|
+
$[18] = storage;
|
|
317
|
+
$[19] = storageKey;
|
|
318
|
+
$[20] = vStore;
|
|
319
|
+
$[21] = t4;
|
|
311
320
|
} else {
|
|
312
|
-
t4 = $[
|
|
321
|
+
t4 = $[21];
|
|
313
322
|
}
|
|
314
323
|
useEffect(t4);
|
|
315
324
|
const repo = source?.repo;
|
|
316
325
|
const tagPrefix = source?.tagPrefix;
|
|
317
326
|
const hasCheck = check !== undefined;
|
|
327
|
+
const vStorePackage = vStore?.packageName;
|
|
328
|
+
const vStoreSite = vStore?.siteUrl;
|
|
329
|
+
const vStoreUrl = prompt.vStoreUrl ?? V_STORE_UPDATES_URL;
|
|
318
330
|
let t5;
|
|
319
|
-
if ($[
|
|
331
|
+
if ($[22] !== currentVersion || $[23] !== enabled || $[24] !== repo || $[25] !== tagPrefix || $[26] !== vStoreUrl) {
|
|
320
332
|
t5 = () => {
|
|
321
333
|
if (!enabled || !currentVersion) {
|
|
322
334
|
return;
|
|
@@ -325,10 +337,11 @@ export function UpdateChecker(t0) {
|
|
|
325
337
|
const run = async () => {
|
|
326
338
|
const {
|
|
327
339
|
check: custom,
|
|
340
|
+
vStore: vStoreSource,
|
|
328
341
|
storage: store,
|
|
329
342
|
storageKey: key
|
|
330
343
|
} = latest.current;
|
|
331
|
-
const found = custom ? await custom(currentVersion) : repo !== undefined && tagPrefix !== undefined ? await fetchGitHubUpdate({
|
|
344
|
+
const found = custom ? await custom(currentVersion) : vStoreSource ? await fetchVStoreUpdate(vStoreSource, currentVersion, vStoreUrl) : repo !== undefined && tagPrefix !== undefined ? await fetchGitHubUpdate({
|
|
332
345
|
repo,
|
|
333
346
|
tagPrefix
|
|
334
347
|
}, currentVersion) : null;
|
|
@@ -345,30 +358,35 @@ export function UpdateChecker(t0) {
|
|
|
345
358
|
cancelled = true;
|
|
346
359
|
};
|
|
347
360
|
};
|
|
348
|
-
$[
|
|
349
|
-
$[
|
|
350
|
-
$[
|
|
351
|
-
$[
|
|
352
|
-
$[
|
|
361
|
+
$[22] = currentVersion;
|
|
362
|
+
$[23] = enabled;
|
|
363
|
+
$[24] = repo;
|
|
364
|
+
$[25] = tagPrefix;
|
|
365
|
+
$[26] = vStoreUrl;
|
|
366
|
+
$[27] = t5;
|
|
353
367
|
} else {
|
|
354
|
-
t5 = $[
|
|
368
|
+
t5 = $[27];
|
|
355
369
|
}
|
|
356
370
|
let t6;
|
|
357
|
-
if ($[
|
|
358
|
-
t6 = [enabled, currentVersion, repo, tagPrefix, hasCheck];
|
|
359
|
-
$[
|
|
360
|
-
$[
|
|
361
|
-
$[
|
|
362
|
-
$[
|
|
363
|
-
$[
|
|
364
|
-
$[
|
|
371
|
+
if ($[28] !== currentVersion || $[29] !== enabled || $[30] !== hasCheck || $[31] !== repo || $[32] !== tagPrefix || $[33] !== vStorePackage || $[34] !== vStoreSite || $[35] !== vStoreUrl) {
|
|
372
|
+
t6 = [enabled, currentVersion, repo, tagPrefix, hasCheck, vStorePackage, vStoreSite, vStoreUrl];
|
|
373
|
+
$[28] = currentVersion;
|
|
374
|
+
$[29] = enabled;
|
|
375
|
+
$[30] = hasCheck;
|
|
376
|
+
$[31] = repo;
|
|
377
|
+
$[32] = tagPrefix;
|
|
378
|
+
$[33] = vStorePackage;
|
|
379
|
+
$[34] = vStoreSite;
|
|
380
|
+
$[35] = vStoreUrl;
|
|
381
|
+
$[36] = t6;
|
|
365
382
|
} else {
|
|
366
|
-
t6 = $[
|
|
383
|
+
t6 = $[36];
|
|
367
384
|
}
|
|
368
385
|
useEffect(t5, t6);
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
386
|
+
const t7 = prompt.showDownload ?? !(vStore !== undefined && vStore.downloadUrl === undefined);
|
|
387
|
+
let t8;
|
|
388
|
+
if ($[37] !== onLater) {
|
|
389
|
+
t8 = current => {
|
|
372
390
|
setUpdate(null);
|
|
373
391
|
const {
|
|
374
392
|
storage: store_0,
|
|
@@ -379,46 +397,47 @@ export function UpdateChecker(t0) {
|
|
|
379
397
|
}
|
|
380
398
|
onLater?.(current);
|
|
381
399
|
};
|
|
382
|
-
$[
|
|
383
|
-
$[
|
|
400
|
+
$[37] = onLater;
|
|
401
|
+
$[38] = t8;
|
|
384
402
|
} else {
|
|
385
|
-
|
|
403
|
+
t8 = $[38];
|
|
386
404
|
}
|
|
387
|
-
let
|
|
388
|
-
if ($[
|
|
389
|
-
|
|
405
|
+
let t9;
|
|
406
|
+
if ($[39] !== onDownload) {
|
|
407
|
+
t9 = current_0 => {
|
|
390
408
|
setUpdate(null);
|
|
391
409
|
onDownload?.(current_0);
|
|
392
410
|
};
|
|
393
|
-
$[
|
|
394
|
-
$[
|
|
411
|
+
$[39] = onDownload;
|
|
412
|
+
$[40] = t9;
|
|
395
413
|
} else {
|
|
396
|
-
|
|
414
|
+
t9 = $[40];
|
|
397
415
|
}
|
|
398
|
-
let
|
|
399
|
-
if ($[
|
|
400
|
-
|
|
416
|
+
let t10;
|
|
417
|
+
if ($[41] !== onOpenVStore) {
|
|
418
|
+
t10 = current_1 => {
|
|
401
419
|
setUpdate(null);
|
|
402
420
|
onOpenVStore?.(current_1);
|
|
403
421
|
};
|
|
404
|
-
$[
|
|
405
|
-
$[
|
|
422
|
+
$[41] = onOpenVStore;
|
|
423
|
+
$[42] = t10;
|
|
406
424
|
} else {
|
|
407
|
-
|
|
425
|
+
t10 = $[42];
|
|
408
426
|
}
|
|
409
|
-
let
|
|
410
|
-
if ($[
|
|
411
|
-
|
|
412
|
-
$[
|
|
413
|
-
$[
|
|
414
|
-
$[
|
|
415
|
-
$[
|
|
416
|
-
$[
|
|
417
|
-
$[
|
|
427
|
+
let t11;
|
|
428
|
+
if ($[43] !== prompt || $[44] !== t10 || $[45] !== t7 || $[46] !== t8 || $[47] !== t9 || $[48] !== update) {
|
|
429
|
+
t11 = <UpdatePrompt {...prompt} showDownload={t7} update={update} onLater={t8} onDownload={t9} onOpenVStore={t10} />;
|
|
430
|
+
$[43] = prompt;
|
|
431
|
+
$[44] = t10;
|
|
432
|
+
$[45] = t7;
|
|
433
|
+
$[46] = t8;
|
|
434
|
+
$[47] = t9;
|
|
435
|
+
$[48] = update;
|
|
436
|
+
$[49] = t11;
|
|
418
437
|
} else {
|
|
419
|
-
|
|
438
|
+
t11 = $[49];
|
|
420
439
|
}
|
|
421
|
-
return
|
|
440
|
+
return t11;
|
|
422
441
|
}
|
|
423
442
|
function _temp3() {}
|
|
424
443
|
function _temp2() {}
|
|
@@ -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/expo
|
|
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);
|
|
@@ -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
|
+
}
|