@vvedantb/native-ui 0.28.0 → 0.30.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 CHANGED
@@ -238,7 +238,19 @@ export default function SignUp() {
238
238
  - `needs_new_password` shows a new-password step (`signIn.resetPassword`), then starts the session.
239
239
  - `onIncomplete(signIn)`: optional. Called only for statuses the built-in UI cannot finish: `needs_identifier`, `needs_first_factor` without an `email_code` or `phone_code` first factor, unknown statuses, and `needs_second_factor` or `needs_client_trust` when no supported strategy (totp, backup code, phone code, email code) exists. The built-in screen always runs `needs_second_factor`, `needs_client_trust` and `needs_new_password`, and runs `needs_first_factor` when an email or phone code exists. When `onIncomplete` is called, the screen shows no message. Without it, those statuses show "This account needs another step to sign in. Finish it on the web." and log the status and strategy ids with `console.warn`. Ignored in `sign-up`.
240
240
  - Keyboard: `AuthScreen` (and so every screen here) pads for the soft keyboard on iOS and Android, including edge-to-edge Android, and scrolls the focused field and the button above it.
241
- - No forgot-password step. An app that needs one keeps its own screen.
241
+ - Sign-up has a confirm-password field. A mismatch blocks the submit and shows "The passwords do not match" under the field, also with `errorDisplay="toast"`.
242
+ - Forgot password: `ResetPasswordScreen` (`SignInScreen` with `mode="reset-password"`, same props) on its own route, and `forgotPasswordHref` on the sign-in screen for the "Forgot password?" link.
243
+
244
+ ```tsx
245
+ // app/(auth)/sign-in.tsx
246
+ <SignInScreen scheme="myapp" signUpHref="/sign-up" forgotPasswordHref="/reset-password" />
247
+
248
+ // app/(auth)/reset-password.tsx
249
+ <ResetPasswordScreen scheme="myapp" signInHref="/sign-in" minPasswordLength={8} />
250
+ ```
251
+
252
+ It asks for the email and sends a code (`signIn.create` with `reset_password_email_code`), checks the code (`attemptFirstFactor`), then takes the new password twice (`signIn.resetPassword`) and starts the session. An account with two-step verification gets that step before the session. "Send a new code" sends another; back returns to the email form. The dashboard must have email-code password reset on. Test IDs: `reset-password-email`, `reset-password-submit`, `reset-password-email-code-code`, `reset-password-resend`, `reset-password-new-password`, `reset-password-confirm-password`, `reset-password-new-password-submit`.
253
+ - Every password field is a `PasswordInput`, so each has the show and hide button.
242
254
 
243
255
  `GoogleSignInButton` (`scheme`, `redirectPath`, `afterAuthHref`, `replaceOptions`, `onSuccess`, `onError`, `label` and the `Button` props), `AuthScreen`, `OrDivider` and `FieldError` build custom screens. The module calls `WebBrowser.maybeCompleteAuthSession()` once when it loads, so the app no longer needs its own call.
244
256
 
@@ -348,7 +360,7 @@ configureTheme({ font: { regular: "Inter_400Regular", medium: "Inter_500Medium",
348
360
  | Actions and fields | `Button` (`default`/`primary`, `secondary`, `outline`, `destructive`, `ghost`, `link`, `tinted`; `sm`/`small`, `default`/`medium`, `lg`/`large`, `icon`; `shape` `pill`/`rounded` from 0.6.0), `IconButton` (0.5.0), `CaptureButton` (0.5.0), `Input`, `SearchInput` (0.3.9), `PasswordInput` (0.11.0), `Textarea`, `Label`, `Select`, `Switch`, `Checkbox`, `LabeledSwitchRow`, `ColorSwatches` (0.5.0), `DateTimeField` (date-only, empty and clearable from 0.5.0) |
349
361
  | Display | `Card` (+ `CardHeader`, `CardTitle`, `CardDescription`, `CardContent`, `CardFooter`; `onPress` from 0.5.0), `Badge`, `StatusDot` (`info` from 0.5.0), `Avatar` (+ `AvatarImage`, `AvatarFallback`, `initials()`), `Separator`, `Progress`, `Spinner`, `CenteredSpinner`, `Skeleton`, `EmptyState` (+ `EmptyState.Root` and parts), `ListRow` (`leading`, `titleEnd`, `control`, `onLongPress` from 0.5.0), `StatGrid` (0.5.0), `SectionLabel` (0.5.0), `Chip`, `Text` (0.5.0, `/primitives` only) |
350
362
  | Navigation | `Tabs` (+ `TabsList`, `TabsTrigger` (`minHeight` from 0.14.0), `TabsContent`), `PillTabs`, `PageIndicator` (0.5.0), `FloatingTabBar`, `FloatingFAB`, `HeaderIconButton`, `ThemeToggle` (0.3.16), `StackPageHeader` (0.5.0) |
351
- | Overlays | `Dialog`, `AlertDialog`, `ConfirmDialog`, `Sheet` (RN `Modal`, each with the web part names; a `SheetContent` or compact `DialogContent` drags down to close), `SheetRow` (0.5.0), `BottomSheetContainer` (`@swmansion/react-native-bottom-sheet`; optional `detents`), `DropdownMenu` (Unreleased; see below) |
363
+ | Overlays | `Dialog`, `AlertDialog`, `ConfirmDialog`, `Sheet` (a `WindowLayer` from 0.29.0: in the app's window under `WindowLayerHost`, else an RN `Modal`; each with the web part names; a `SheetContent` or compact `DialogContent` drags down to close), `SheetRow` (0.5.0), `BottomSheetContainer` (`@swmansion/react-native-bottom-sheet`; optional `detents`), `DropdownMenu` (Unreleased; see below) |
352
364
  | Selection | `BulkActionBar` (Unreleased; see below) |
353
365
  | Feedback | `toast()` and `<Toaster />` |
354
366
  | Brand and upgrade | `APP_ICONS`, `IconVibot` and the other `Icon*`, `AppMark`, `AppWordmark`, `GoogleMark` (0.3.15), `FAMILY_APPS`, `V_PRO_APP_BENEFITS`, `UpgradeToProCard`, `PricingModal` |
@@ -621,7 +633,7 @@ import {
621
633
 
622
634
  ## DropdownMenu (Unreleased)
623
635
 
624
- A small menu anchored to its trigger, the native counterpart of the web `DropdownMenu`. On `/primitives` and the root. From 0.12.1 the backdrop and menu sit in a full-size `View` inside the `Modal`, so the menu stays above tab bars and glass layers.
636
+ A small menu anchored to its trigger, the native counterpart of the web `DropdownMenu`. On `/primitives` and the root. From 0.12.1 the backdrop and menu sit in a full-size `View` inside the overlay, so the menu stays above tab bars and glass layers. From 0.29.0 the overlay is a `WindowLayer`: in the app's window under `WindowLayerHost`, so a chat under it keeps its place, else an RN `Modal`.
625
637
 
626
638
  ```tsx
627
639
  <DropdownMenu>
@@ -643,7 +655,7 @@ A small menu anchored to its trigger, the native counterpart of the web `Dropdow
643
655
  | --- | --- |
644
656
  | `DropdownMenu` | `open`, `defaultOpen`, `onOpenChange`. Holds the open state; renders no view. |
645
657
  | `DropdownMenuTrigger` | `Pressable` props and `asChild`. On press it measures itself (`measureInWindow`) and opens the menu; pressed again it closes it. Reports `expanded`. With `asChild` the child must pass `ref` on to its native view (`Button` and `IconButton` do). |
646
- | `DropdownMenuContent` | `align` (`"start"`, default, or `"end"`), `sideOffset` (default 4), `View` props. A transparent RN `Modal`; the menu sits under the trigger and flips above it when it does not fit below. |
658
+ | `DropdownMenuContent` | `align` (`"start"`, default, or `"end"`), `sideOffset` (default 4), `View` props. A `WindowLayer` (a transparent RN `Modal` without `WindowLayerHost`); the menu sits under the trigger and flips above it when it does not fit below. |
647
659
  | `DropdownMenuLabel` | `children`. |
648
660
  | `DropdownMenuItem` | `children`, `onSelect`, `icon` (a Tabler icon), `destructive`, `disabled`, `closeOnSelect` (default `true`). |
649
661
  | `DropdownMenuRadioItem` | The same without `icon` and `destructive`, plus `checked`. |
@@ -1,7 +1,7 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
2
  import * as Slot from "@rn-primitives/slot";
3
3
  import { createContext, useContext, useEffect, useRef, useState } from "react";
4
- import { Modal, Pressable, ScrollView, StyleSheet, Text, View, useWindowDimensions } from "react-native";
4
+ import { Pressable, ScrollView, StyleSheet, Text, View, useWindowDimensions } from "react-native";
5
5
  import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
6
6
  import { useSafeAreaInsets } from "react-native-safe-area-context";
7
7
  import { IconCheck } from "@tabler/icons-react-native";
@@ -16,6 +16,7 @@ import { tokens } from "./tokens";
16
16
  import { useReduceMotion } from "./useReduceMotion";
17
17
  import { useScheme } from "./useScheme";
18
18
  import { useControllableState } from "./primitives/use-controllable-state";
19
+ import { WindowLayer } from "./primitives/window-layer";
19
20
 
20
21
  /**
21
22
  * Sizes from the web menu classes (`_menu-classes.ts`): content `min-w-[12rem]
@@ -245,7 +246,8 @@ export function dropdownMenuPosition({
245
246
  };
246
247
  }
247
248
  /**
248
- * The menu in a transparent RN `Modal`: the opaque overlay surface of
249
+ * The menu in a `WindowLayer` (in the app's window under `WindowLayerHost`, so
250
+ * a chat under it keeps its place; else a transparent `Modal`): the opaque overlay surface of
249
251
  * `Dialog` and `Sheet` (`FloatingSurface` without blur, with the floating
250
252
  * shadow) at radius 16, at least 192 wide, `p-1.5`, scrolling when taller than
251
253
  * the room. A tap outside, Android back and the VoiceOver escape gesture close
@@ -254,7 +256,7 @@ export function dropdownMenuPosition({
254
256
  * 100 ms. With Reduce Motion on, it appears and leaves at once.
255
257
  */
256
258
  export function DropdownMenuContent(t0) {
257
- const $ = _c(74);
259
+ const $ = _c(76);
258
260
  let children;
259
261
  let className;
260
262
  let props;
@@ -286,11 +288,12 @@ export function DropdownMenuContent(t0) {
286
288
  t1 = $[6];
287
289
  }
288
290
  const align = t1 === undefined ? "start" : t1;
291
+ const menu = useMenu("DropdownMenuContent");
289
292
  const {
290
293
  open,
291
294
  setOpen,
292
295
  trigger
293
- } = useMenu("DropdownMenuContent");
296
+ } = menu;
294
297
  const window = useWindowDimensions();
295
298
  const insets = useSafeAreaInsets();
296
299
  const reduceMotion = useReduceMotion();
@@ -423,6 +426,9 @@ export function DropdownMenuContent(t0) {
423
426
  }
424
427
  const position = t9;
425
428
  const transformOrigin = `${align === "end" ? 100 : 0}% ${position.bottom === undefined ? 0 : 100}%`;
429
+ if (!shown) {
430
+ return null;
431
+ }
426
432
  let t10;
427
433
  if ($[33] === Symbol.for("react.memo_cache_sentinel")) {
428
434
  t10 = {
@@ -559,16 +565,24 @@ export function DropdownMenuContent(t0) {
559
565
  t26 = $[69];
560
566
  }
561
567
  let t27;
562
- if ($[70] !== close || $[71] !== shown || $[72] !== t26) {
563
- t27 = <Modal visible={shown} transparent={true} animationType="none" statusBarTranslucent={true} onRequestClose={close}>{t26}</Modal>;
564
- $[70] = close;
565
- $[71] = shown;
566
- $[72] = t26;
567
- $[73] = t27;
568
+ if ($[70] !== menu || $[71] !== t26) {
569
+ t27 = <MenuContext.Provider value={menu}>{t26}</MenuContext.Provider>;
570
+ $[70] = menu;
571
+ $[71] = t26;
572
+ $[72] = t27;
573
+ } else {
574
+ t27 = $[72];
575
+ }
576
+ let t28;
577
+ if ($[73] !== close || $[74] !== t27) {
578
+ t28 = <WindowLayer onRequestClose={close} fade={false}>{t27}</WindowLayer>;
579
+ $[73] = close;
580
+ $[74] = t27;
581
+ $[75] = t28;
568
582
  } else {
569
- t27 = $[73];
583
+ t28 = $[75];
570
584
  }
571
- return t27;
585
+ return t28;
572
586
  }
573
587
 
574
588
  /** Item type and icon size: the web `text-sm` with a 16 icon in 48 rows, or `text-lg` with a 22 icon and 56 rows with larger text. */
@@ -8,6 +8,8 @@ import { createContext, useContext } from "react";
8
8
  * the `FlatList` of `ConversationList`. `scrollToEnd` goes to the newest
9
9
  * message, which is offset 0 in an inverted list. `scrollTo` goes to an
10
10
  * offset; only the `ScrollView` has it, so call it as `scrollTo?.(...)`.
11
+ * `scrollToIndex` brings one row of the list's `data` into view (a find in
12
+ * the thread); only the `FlatList` has it. `viewPosition` 0.5 centres it.
11
13
  */
12
14
 
13
15
  export const ConversationContext = createContext(null);
@@ -366,6 +366,9 @@ export function ConversationList({
366
366
  inset: 0,
367
367
  keyboardMoving: false
368
368
  });
369
+ // The list, and the row `scrollToIndex` last asked for, for its retry when that row was not drawn.
370
+ const listRef = useRef(null);
371
+ const indexTarget = useRef(null);
369
372
  // Not inverted: hidden until the first jump to the end (see above). An
370
373
  // empty list (a spinner, an empty state) shows at once.
371
374
  const hasRows = (props.data?.length ?? 0) > 0;
@@ -400,7 +403,7 @@ export function ConversationList({
400
403
  }
401
404
  // The newest message's offset: inverted, 0 less the space before it.
402
405
  const end = () => inverted ? size.current.inset > 0 ? -size.current.inset : 0 : Math.max(0, size.current.content + size.current.inset - size.current.view);
403
- const list_0 = <FlatList className={cn("flex-1", className)}
406
+ const list_1 = <FlatList className={cn("flex-1", className)}
404
407
  // Inverted, the column's end is the top: a short thread sits there.
405
408
  contentContainerClassName={cn("px-3 py-3", inverted && "grow justify-end", contentContainerClassName)} {...wired} style={[wired.style, !inverted && hasRows && !placed ? styles.hidden : null]}
406
409
  // At the bottom, a new message shows at offset 0; scrolled up, it must not move what the reader sees.
@@ -412,18 +415,39 @@ export function ConversationList({
412
415
  size.current.keyboardMoving = moving;
413
416
  // The closing menu's window hands the focus back with a keyboard event: frozen until it ends.
414
417
  if (!moving) conversation.settleOverlay();
415
- }} /> : props.renderScrollComponent} ref={list => {
416
- conversation.scrollRef.current = list && {
417
- scrollToEnd: options => list.scrollToOffset({
418
+ }} /> : props.renderScrollComponent}
419
+ // A row the list has not drawn yet (it draws only those near the view):
420
+ // go to its estimated offset, which draws it, then to the row itself.
421
+ onScrollToIndexFailed={props.onScrollToIndexFailed ?? (info => {
422
+ const list = listRef.current;
423
+ const target = indexTarget.current;
424
+ if (!list || !target || target.index !== info.index || target.tries >= 3) return;
425
+ target.tries += 1;
426
+ list.scrollToOffset({
427
+ offset: info.averageItemLength * info.index,
428
+ animated: false
429
+ });
430
+ requestAnimationFrame(() => list.scrollToIndex(target));
431
+ })} ref={list_0 => {
432
+ listRef.current = list_0;
433
+ conversation.scrollRef.current = list_0 && {
434
+ scrollToEnd: options => list_0.scrollToOffset({
418
435
  offset: end(),
419
436
  animated: options?.animated
420
- })
437
+ }),
438
+ scrollToIndex: options_0 => {
439
+ indexTarget.current = {
440
+ ...options_0,
441
+ tries: 0
442
+ };
443
+ list_0.scrollToIndex(options_0);
444
+ }
421
445
  };
422
446
  }} />;
423
- if (!keyboard) return list_0;
447
+ if (!keyboard) return list_1;
424
448
  // The keyboard follows the finger from the composer's top: the dock less the inset it pads.
425
449
  return <keyboard.GestureArea offset={Math.max(0, conversation.dockHeight - insets.bottom)} style={styles.fill}>
426
- {list_0}
450
+ {list_1}
427
451
  </keyboard.GestureArea>;
428
452
  }
429
453
 
@@ -14,6 +14,9 @@ import { authErrorMessage, DEFAULT_STAGE_TIMEOUT_MS, isAuthTimeoutError, logAuth
14
14
  import { SecondFactorScreen } from "./SecondFactorScreen";
15
15
  import { pickFirstFactorStrategy, pickSecondFactorStrategy, prepareFirstFactorIfNeeded, submitFirstFactor, supportedFirstFactorStrategies, supportedSecondFactorStrategies, useSecondFactor } from "./totp";
16
16
  import { GoogleSignInButton } from "./GoogleSignInButton";
17
+ /** The first factor that emails a password-reset code. */
18
+ const RESET_STRATEGY = "reset_password_email_code";
19
+
17
20
  /** The messages the screen can show. Generic: none names a provider. */
18
21
  export const AUTH_MESSAGES = {
19
22
  missingFields: "Enter your email and password",
@@ -45,7 +48,17 @@ export const AUTH_MESSAGES = {
45
48
  passwordMismatch: "The passwords do not match",
46
49
  passwordTooShort: "Use a longer password",
47
50
  resetPasswordFailed: "Could not set the new password",
48
- setPassword: "Set password"
51
+ setPassword: "Set password",
52
+ missingNewPassword: "Enter a new password",
53
+ confirmSignUpPasswordLabel: "Confirm password",
54
+ forgotPassword: "Forgot password?",
55
+ resetTitle: "Reset password",
56
+ resetSubtitle: "Enter your email and we will send you a code.",
57
+ resetNewPasswordDescription: "Choose a new password for your account.",
58
+ missingEmail: "Enter your email",
59
+ sendResetCode: "Send code",
60
+ sendResetFailed: "Could not send the code",
61
+ resendCode: "Send a new code"
49
62
  };
50
63
 
51
64
  /**
@@ -94,7 +107,13 @@ function secondFactorCopy(strategy, clientTrust) {
94
107
  * code and checks it before the session starts. On success it calls
95
108
  * `onSuccess`, or `router.replace(afterAuthHref, replaceOptions)`.
96
109
  *
97
- * Forgot-password is not here: an app that needs it keeps its own screen.
110
+ * Sign-up has a confirm-password field: a mismatch blocks the submit and shows
111
+ * under the field, whatever `errorDisplay` is.
112
+ *
113
+ * `mode="reset-password"` (`ResetPasswordScreen`) is the forgot-password flow:
114
+ * email, then the emailed code, then a new password typed twice. It ends
115
+ * signed in, through the same second-factor step when the account has one.
116
+ * `forgotPasswordHref` links the sign-in form to it.
98
117
  */
99
118
  export function SignInScreen({
100
119
  mode = "sign-in",
@@ -109,6 +128,7 @@ export function SignInScreen({
109
128
  googleLabel,
110
129
  signUpHref,
111
130
  signInHref,
131
+ forgotPasswordHref,
112
132
  minPasswordLength,
113
133
  errorDisplay = "toast",
114
134
  testIDPrefix,
@@ -136,6 +156,11 @@ export function SignInScreen({
136
156
  const [pendingNewPassword, setPendingNewPassword] = useState(false);
137
157
  const [newPassword, setNewPassword] = useState("");
138
158
  const [confirmPassword, setConfirmPassword] = useState("");
159
+ const [signUpConfirm, setSignUpConfirm] = useState("");
160
+ const [mismatch, setMismatch] = useState(false);
161
+ const [pendingResetCode, setPendingResetCode] = useState(false);
162
+ const [resetLoading, setResetLoading] = useState(false);
163
+ const [resetCodeError, setResetCodeError] = useState("");
139
164
  const secondFactor = useSecondFactor({
140
165
  stageTimeoutMs
141
166
  });
@@ -145,6 +170,7 @@ export function SignInScreen({
145
170
  const passwordField = useRef(null);
146
171
  const confirmField = useRef(null);
147
172
  const signUp = mode === "sign-up";
173
+ const reset = mode === "reset-password";
148
174
  const id = name => `${testIDPrefix ?? mode}-${name}`;
149
175
  const fail = (heading, message) => {
150
176
  if (errorDisplay === "inline") setError(message);else toast.error(heading, message === heading ? undefined : {
@@ -218,9 +244,11 @@ export function SignInScreen({
218
244
  done();
219
245
  } else if (status === "needs_new_password") {
220
246
  setPendingFirstFactor(false);
247
+ setPendingResetCode(false);
221
248
  setPendingNewPassword(true);
222
249
  } else if (status === "needs_second_factor" || status === "needs_client_trust") {
223
250
  setPendingFirstFactor(false);
251
+ setPendingResetCode(false);
224
252
  await startSecondFactor(attempt_3, status === "needs_client_trust");
225
253
  } else if (status === "needs_first_factor" && afterCreate) {
226
254
  await startFirstFactor(attempt_3);
@@ -263,7 +291,7 @@ export function SignInScreen({
263
291
  setActive: setActive_0
264
292
  } = signInState;
265
293
  if (!isLoaded_0 || !signIn_1 || !setActive_0 || submitting) return;
266
- if (!newPassword) return fail(AUTH_MESSAGES.resetPasswordFailed, AUTH_MESSAGES.missingFields);
294
+ if (!newPassword) return fail(AUTH_MESSAGES.resetPasswordFailed, AUTH_MESSAGES.missingNewPassword);
267
295
  if (minPasswordLength && newPassword.length < minPasswordLength) {
268
296
  return fail(AUTH_MESSAGES.resetPasswordFailed, `Use at least ${minPasswordLength} characters for the password`);
269
297
  }
@@ -276,11 +304,17 @@ export function SignInScreen({
276
304
  const result_0 = await withAuthTimeout(signIn_1.resetPassword({
277
305
  password: newPassword
278
306
  }), "reset-password", stageTimeoutMs);
279
- if (result_0.status === "complete" && result_0.createdSessionId) {
307
+ // Clerk's `SignInStatus` omits `needs_client_trust`: widen before comparing.
308
+ const afterReset = result_0.status;
309
+ if (afterReset === "complete" && result_0.createdSessionId) {
280
310
  await withAuthTimeout(setActive_0({
281
311
  session: result_0.createdSessionId
282
312
  }), "set-active", stageTimeoutMs);
283
313
  done();
314
+ } else if (afterReset === "needs_second_factor" || afterReset === "needs_client_trust") {
315
+ // A reset on an account with two-step verification: the code step, then the session.
316
+ setPendingNewPassword(false);
317
+ await startSecondFactor(result_0, afterReset === "needs_client_trust");
284
318
  } else if (onIncomplete) {
285
319
  onIncomplete(result_0);
286
320
  } else {
@@ -319,6 +353,87 @@ export function SignInScreen({
319
353
  setSubmitting(false);
320
354
  }
321
355
  };
356
+
357
+ // Emails the reset code. Throws what the call throws.
358
+ const requestResetCode = async () => {
359
+ const {
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);
367
+ };
368
+ const onResetRequest = async () => {
369
+ const {
370
+ isLoaded: isLoaded_2,
371
+ signIn: signIn_4
372
+ } = signInState;
373
+ if (!isLoaded_2 || !signIn_4 || submitting) return;
374
+ if (!email.trim()) return fail(AUTH_MESSAGES.sendResetFailed, AUTH_MESSAGES.missingEmail);
375
+ setSubmitting(true);
376
+ setError("");
377
+ try {
378
+ await requestResetCode();
379
+ setResetCodeError("");
380
+ setPendingResetCode(true);
381
+ } catch (caught_2) {
382
+ logAuthFailure("create", caught_2);
383
+ fail(AUTH_MESSAGES.sendResetFailed, authErrorMessage(caught_2, AUTH_MESSAGES.sendResetFailed));
384
+ } finally {
385
+ setSubmitting(false);
386
+ }
387
+ };
388
+ const onResetResend = async () => {
389
+ const {
390
+ isLoaded: isLoaded_3,
391
+ signIn: signIn_5
392
+ } = signInState;
393
+ if (!isLoaded_3 || !signIn_5 || resetLoading) return;
394
+ setResetLoading(true);
395
+ setResetCodeError("");
396
+ try {
397
+ await requestResetCode();
398
+ } catch (caught_3) {
399
+ logAuthFailure("create", caught_3);
400
+ setResetCodeError(authErrorMessage(caught_3, AUTH_MESSAGES.sendResetFailed));
401
+ } finally {
402
+ setResetLoading(false);
403
+ }
404
+ };
405
+
406
+ // Checks the emailed code. A good code gives `needs_new_password`, which `routeAttempt` shows.
407
+ const onResetCode = async resetCode => {
408
+ const {
409
+ isLoaded: isLoaded_4,
410
+ signIn: signIn_6
411
+ } = signInState;
412
+ if (!isLoaded_4 || !signIn_6 || resetLoading) return;
413
+ setResetLoading(true);
414
+ setResetCodeError("");
415
+ try {
416
+ const attempt_5 = await withAuthTimeout(signIn_6.attemptFirstFactor({
417
+ strategy: RESET_STRATEGY,
418
+ code: resetCode
419
+ }), "attempt-first-factor", stageTimeoutMs);
420
+ const status_0 = attempt_5.status;
421
+ const known = ["complete", "needs_new_password", "needs_second_factor", "needs_client_trust"];
422
+ if (status_0 && known.includes(status_0)) {
423
+ await routeAttempt(attempt_5, false);
424
+ } else if (onIncomplete) {
425
+ onIncomplete(attempt_5);
426
+ } else {
427
+ warnIncomplete(attempt_5);
428
+ setResetCodeError(AUTH_MESSAGES.needsAnotherStep);
429
+ }
430
+ } catch (caught_4) {
431
+ if (isAuthTimeoutError(caught_4)) logAuthFailure("attempt-first-factor", caught_4);
432
+ setResetCodeError(authErrorMessage(caught_4, AUTH_MESSAGES.verifyFailed));
433
+ } finally {
434
+ setResetLoading(false);
435
+ }
436
+ };
322
437
  const onSecondFactor = async secondFactorCode => {
323
438
  const result_1 = await secondFactor.submit(secondFactorCode);
324
439
  if (result_1.ok) done();
@@ -328,6 +443,8 @@ export function SignInScreen({
328
443
  setPendingSecondFactor(false);
329
444
  setPendingFirstFactor(false);
330
445
  setFirstError("");
446
+ setPendingResetCode(false);
447
+ setResetCodeError("");
331
448
  setPendingNewPassword(false);
332
449
  setNewPassword("");
333
450
  setConfirmPassword("");
@@ -337,43 +454,49 @@ export function SignInScreen({
337
454
  };
338
455
  const onSignUp = async () => {
339
456
  const {
340
- isLoaded: isLoaded_2,
341
- signUp: attempt_5
457
+ isLoaded: isLoaded_5,
458
+ signUp: attempt_6
342
459
  } = signUpState;
343
- if (!isLoaded_2 || !attempt_5 || submitting) return;
460
+ if (!isLoaded_5 || !attempt_6 || submitting) return;
344
461
  if (!email || !password) return fail(AUTH_MESSAGES.signUpFailed, AUTH_MESSAGES.missingFields);
345
462
  if (minPasswordLength && password.length < minPasswordLength) {
346
463
  return fail(AUTH_MESSAGES.signUpFailed, `Use at least ${minPasswordLength} characters for the password`);
347
464
  }
465
+ if (password !== signUpConfirm) {
466
+ // Always under the confirm field, also with `errorDisplay="toast"`.
467
+ setError("");
468
+ setMismatch(true);
469
+ return;
470
+ }
348
471
  setSubmitting(true);
349
472
  setError("");
350
473
  try {
351
- await attempt_5.create({
474
+ await attempt_6.create({
352
475
  emailAddress: email,
353
476
  password
354
477
  });
355
- await attempt_5.prepareEmailAddressVerification({
478
+ await attempt_6.prepareEmailAddressVerification({
356
479
  strategy: "email_code"
357
480
  });
358
481
  setPendingVerification(true);
359
- } catch (caught_2) {
360
- fail(AUTH_MESSAGES.signUpFailed, authErrorMessage(caught_2, AUTH_MESSAGES.signUpFailed));
482
+ } catch (caught_5) {
483
+ fail(AUTH_MESSAGES.signUpFailed, authErrorMessage(caught_5, AUTH_MESSAGES.signUpFailed));
361
484
  } finally {
362
485
  setSubmitting(false);
363
486
  }
364
487
  };
365
488
  const onVerify = async () => {
366
489
  const {
367
- isLoaded: isLoaded_3,
368
- signUp: attempt_6,
490
+ isLoaded: isLoaded_6,
491
+ signUp: attempt_7,
369
492
  setActive: setActive_2
370
493
  } = signUpState;
371
- if (!isLoaded_3 || !attempt_6 || !setActive_2 || submitting) return;
494
+ if (!isLoaded_6 || !attempt_7 || !setActive_2 || submitting) return;
372
495
  if (!code) return fail(AUTH_MESSAGES.verifyFailed, AUTH_MESSAGES.missingCode);
373
496
  setSubmitting(true);
374
497
  setError("");
375
498
  try {
376
- const result_2 = await attempt_6.attemptEmailAddressVerification({
499
+ const result_2 = await attempt_7.attemptEmailAddressVerification({
377
500
  code
378
501
  });
379
502
  if (result_2.status === "complete" && result_2.createdSessionId) {
@@ -384,27 +507,28 @@ export function SignInScreen({
384
507
  } else {
385
508
  fail(AUTH_MESSAGES.verifyFailed, AUTH_MESSAGES.needsAnotherStep);
386
509
  }
387
- } catch (caught_3) {
388
- fail(AUTH_MESSAGES.verifyFailed, authErrorMessage(caught_3, AUTH_MESSAGES.verifyFailed));
510
+ } catch (caught_6) {
511
+ fail(AUTH_MESSAGES.verifyFailed, authErrorMessage(caught_6, AUTH_MESSAGES.verifyFailed));
389
512
  } finally {
390
513
  setSubmitting(false);
391
514
  }
392
515
  };
393
- const linkHref = signUp ? signInHref : signUpHref;
516
+ const toSignIn = signUp || reset;
517
+ const linkHref = toSignIn ? signInHref : signUpHref;
394
518
  const footerRow = <>
395
519
  {linkHref && !pendingVerification ? <>
396
520
  <Text className="font-instrument-sans text-sm" style={textStyle("muted", colorScheme)}>
397
- {signUp ? "Already have an account?" : "Don't have an account?"}
521
+ {reset ? "Remembered your password?" : signUp ? "Already have an account?" : "Don't have an account?"}
398
522
  </Text>
399
- <Button testID={id(signUp ? "sign-in-link" : "sign-up-link")} variant="link" size="sm" fullWidth={false} onPress={() => router.push(linkHref)}>
400
- {signUp ? "Sign in" : "Sign up"}
523
+ <Button testID={id(toSignIn ? "sign-in-link" : "sign-up-link")} variant="link" size="sm" fullWidth={false} onPress={() => router.push(linkHref)}>
524
+ {toSignIn ? "Sign in" : "Sign up"}
401
525
  </Button>
402
526
  </> : null}
403
527
  {footer}
404
528
  </>;
405
529
  const hasFooter = Boolean(linkHref && !pendingVerification || footer);
406
530
  if (pendingNewPassword) {
407
- return <AuthScreen testID={id("new-password-screen")} title={AUTH_MESSAGES.newPasswordTitle} subtitle={AUTH_MESSAGES.newPasswordDescription} header={header}>
531
+ return <AuthScreen testID={id("new-password-screen")} title={AUTH_MESSAGES.newPasswordTitle} subtitle={reset ? AUTH_MESSAGES.resetNewPasswordDescription : AUTH_MESSAGES.newPasswordDescription} header={header}>
408
532
  <PasswordInput testID={id("new-password")} accessibilityLabel={AUTH_MESSAGES.newPasswordLabel} autoCapitalize="none" autoComplete="new-password" textContentType="newPassword" autoFocus returnKeyType="next" submitBehavior="submit" onSubmitEditing={() => confirmField.current?.focus()} value={newPassword} placeholder={AUTH_MESSAGES.newPasswordLabel} onChangeText={setNewPassword} />
409
533
  <PasswordInput testID={id("confirm-password")} ref={confirmField} accessibilityLabel={AUTH_MESSAGES.confirmPasswordLabel} autoCapitalize="none" autoComplete="new-password" textContentType="newPassword" returnKeyType="go" value={confirmPassword} placeholder={AUTH_MESSAGES.confirmPasswordLabel} onChangeText={setConfirmPassword} onSubmitEditing={() => void onNewPassword()} />
410
534
  <FieldError testID={id("error")} message={error} />
@@ -412,10 +536,15 @@ export function SignInScreen({
412
536
  {AUTH_MESSAGES.setPassword}
413
537
  </Button>
414
538
  <Button testID={id("new-password-back")} variant="ghost" onPress={onSecondFactorBack}>
415
- Use a different account
539
+ {reset ? "Use a different email" : "Use a different account"}
416
540
  </Button>
417
541
  </AuthScreen>;
418
542
  }
543
+ if (pendingResetCode && !pendingSecondFactor) {
544
+ return <SecondFactorScreen key="reset-code" title={AUTH_MESSAGES.emailCodeTitle} description={AUTH_MESSAGES.emailCodeDescription} footer={<Button testID={id("resend")} variant="link" size="sm" fullWidth={false} disabled={resetLoading} onPress={() => void onResetResend()}>
545
+ {AUTH_MESSAGES.resendCode}
546
+ </Button>} onSubmit={onResetCode} error={resetCodeError} loading={resetLoading} onBack={onSecondFactorBack} backLabel="Use a different email" header={header} testIDPrefix={id("email-code")} />;
547
+ }
419
548
  if (pendingFirstFactor && !pendingSecondFactor && !pendingNewPassword) {
420
549
  const others = supportedFirstFactorStrategies(firstFactors).filter(strategy_3 => strategy_3 !== firstStrategy);
421
550
  const switchTo = others[0] ?? null;
@@ -452,16 +581,31 @@ export function SignInScreen({
452
581
  </Button>
453
582
  </AuthScreen>;
454
583
  }
455
- return <AuthScreen testID={id("screen")} title={title ?? (signUp ? "Create account" : "Welcome back")} subtitle={subtitle ?? (signUp ? "Sign up to get started" : "Sign in to continue")} header={header} footer={hasFooter ? footerRow : undefined}>
456
- {showGoogle ? <>
584
+ return <AuthScreen testID={id("screen")} title={title ?? (reset ? AUTH_MESSAGES.resetTitle : signUp ? "Create account" : "Welcome back")} subtitle={subtitle ?? (reset ? AUTH_MESSAGES.resetSubtitle : signUp ? "Sign up to get started" : "Sign in to continue")} header={header} footer={hasFooter ? footerRow : undefined}>
585
+ {showGoogle && !reset ? <>
457
586
  <GoogleSignInButton testID={id("google")} scheme={scheme} redirectPath={redirectPath} afterAuthHref={afterAuthHref} replaceOptions={replaceOptions} onSuccess={onSuccess} onError={message_0 => fail(message_0, message_0)} label={googleLabel} disabled={submitting} />
458
587
  <OrDivider />
459
588
  </> : null}
460
- <Input testID={id("email")} accessibilityLabel="Email" autoCapitalize="none" autoComplete="email" textContentType="emailAddress" keyboardType="email-address" returnKeyType="next" submitBehavior="submit" onSubmitEditing={() => passwordField.current?.focus()} value={email} placeholder="Email" onChangeText={setEmail} />
461
- <PasswordInput testID={id("password")} ref={passwordField} accessibilityLabel="Password" autoCapitalize="none" autoComplete={signUp ? "new-password" : "password"} textContentType={signUp ? "newPassword" : "password"} returnKeyType="go" value={password} placeholder="Password" onChangeText={setPassword} onSubmitEditing={() => void (signUp ? onSignUp() : onSignIn())} />
589
+ <Input testID={id("email")} accessibilityLabel="Email" autoCapitalize="none" autoComplete="email" textContentType="emailAddress" keyboardType="email-address" returnKeyType={reset ? "go" : "next"} submitBehavior={reset ? undefined : "submit"} onSubmitEditing={() => reset ? void onResetRequest() : passwordField.current?.focus()} value={email} placeholder="Email" onChangeText={setEmail} />
590
+ {reset ? null : <PasswordInput testID={id("password")} ref={passwordField} accessibilityLabel="Password" autoCapitalize="none" autoComplete={signUp ? "new-password" : "password"} textContentType={signUp ? "newPassword" : "password"} returnKeyType={signUp ? "next" : "go"} submitBehavior={signUp ? "submit" : undefined} value={password} placeholder="Password" onChangeText={text => {
591
+ setPassword(text);
592
+ setMismatch(false);
593
+ }} onSubmitEditing={() => signUp ? confirmField.current?.focus() : void onSignIn()} />}
594
+ {signUp ? <>
595
+ <PasswordInput testID={id("confirm-password")} ref={confirmField} accessibilityLabel={AUTH_MESSAGES.confirmSignUpPasswordLabel} autoCapitalize="none" autoComplete="new-password" textContentType="newPassword" returnKeyType="go" value={signUpConfirm} placeholder={AUTH_MESSAGES.confirmSignUpPasswordLabel} onChangeText={text_0 => {
596
+ setSignUpConfirm(text_0);
597
+ setMismatch(false);
598
+ }} onSubmitEditing={() => void onSignUp()} />
599
+ <FieldError testID={id("confirm-error")} message={mismatch ? AUTH_MESSAGES.passwordMismatch : ""} />
600
+ </> : null}
601
+ {!signUp && !reset && forgotPasswordHref ? <View className="items-end">
602
+ <Button testID={id("forgot-password")} variant="link" size="sm" fullWidth={false} onPress={() => router.push(forgotPasswordHref)}>
603
+ {AUTH_MESSAGES.forgotPassword}
604
+ </Button>
605
+ </View> : null}
462
606
  <FieldError testID={id("error")} message={error} />
463
- <Button testID={id("submit")} loading={submitting} onPress={() => void (signUp ? onSignUp() : onSignIn())}>
464
- {signUp ? "Create account" : "Sign in"}
607
+ <Button testID={id("submit")} loading={submitting} onPress={() => void (reset ? onResetRequest() : signUp ? onSignUp() : onSignIn())}>
608
+ {reset ? AUTH_MESSAGES.sendResetCode : signUp ? "Create account" : "Sign in"}
465
609
  </Button>
466
610
  {/* Bot protection mounts its widget here on web sign-up. */}
467
611
  {signUp ? <View nativeID="clerk-captcha" /> : null}
@@ -480,3 +624,16 @@ export function SignUpScreen(props) {
480
624
  }
481
625
  return t0;
482
626
  }
627
+ /** `SignInScreen` with `mode="reset-password"`: the forgot-password flow. */
628
+ export function ResetPasswordScreen(props) {
629
+ const $ = _c(2);
630
+ let t0;
631
+ if ($[0] !== props) {
632
+ t0 = <SignInScreen {...props} mode="reset-password" />;
633
+ $[0] = props;
634
+ $[1] = t0;
635
+ } else {
636
+ t0 = $[1];
637
+ }
638
+ return t0;
639
+ }
@@ -6,6 +6,6 @@ export { AuthProviders } from "./AuthProviders";
6
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
- export { SignInScreen, SignUpScreen, AUTH_MESSAGES } from "./SignInScreen";
9
+ export { SignInScreen, SignUpScreen, ResetPasswordScreen, AUTH_MESSAGES } from "./SignInScreen";
10
10
  export { SecondFactorScreen } from "./SecondFactorScreen";
11
11
  export { submitTotpSecondFactor, submitSecondFactor, prepareSecondFactorIfNeeded, prepareFirstFactorIfNeeded, submitFirstFactor, pickFirstFactorStrategy, supportedFirstFactorStrategies, FIRST_FACTOR_PREFERENCE, pickSecondFactorStrategy, supportedSecondFactorStrategies, SECOND_FACTOR_PREFERENCE, useSecondFactor, TOTP_MESSAGES } from "./totp";