Skip to content

auth wiring - #18

Merged
OumB2021 merged 4 commits into
mainfrom
authLogic
Jul 4, 2026
Merged

auth wiring#18
OumB2021 merged 4 commits into
mainfrom
authLogic

Conversation

@OumB2021

@OumB2021 OumB2021 commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Completed the authentication flow with Forgot Password, Sign In (2-step), Sign Up, and Email Verification screens.
    • Added an authenticated API request hook that uses an auth token when available.
  • Bug Fixes
    • Improved sign-in/sign-up/verification UX with proper loading states, clearer error handling, and prevention of double submissions.
    • Enhanced sign-in reliability via secure token caching and consistent session activation.
  • UI / Chores
    • Removed the temporary home sign-in action and refreshed the home header layout.

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 34ba6e7f-a251-4ac7-a0a0-451ad83abe96

📥 Commits

Reviewing files that changed from the base of the PR and between 2fc7af7 and 823261a.

📒 Files selected for processing (2)
  • apps/mobile/app/(auth)/sign-in-verify.tsx
  • apps/mobile/app/(auth)/sign-in.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/mobile/app/(auth)/sign-in.tsx
  • apps/mobile/app/(auth)/sign-in-verify.tsx

📝 Walkthrough

Walkthrough

Adds Clerk-based authentication, email verification, and auth-aware routing to the mobile app, wires in secure token storage and an authenticated API hook, and updates home and auth screens to match the new flow.

Changes

Clerk authentication integration

Layer / File(s) Summary
Clerk provider, token cache, and API hook
apps/mobile/lib/clerk.ts, apps/mobile/lib/api.ts, apps/mobile/app/_layout.tsx, apps/mobile/package.json, package.json
Adds secure token caching, a Clerk-backed API hook with timeout and bearer headers, Clerk provider setup in the root layout, and dependency/package-manager updates.
Auth-aware root redirect
apps/mobile/app/index.tsx
Waits for Clerk auth state before redirecting signed-in users to /(tabs)/home or signed-out users to /(auth)/sign-in.
Sign-in screen Clerk integration
apps/mobile/app/(auth)/sign-in.tsx
Replaces placeholder sign-in logic with Clerk-backed submission, error handling, second-factor routing, and loading-state UI.
Sign-up screen Clerk integration
apps/mobile/app/(auth)/sign-up.tsx
Replaces placeholder sign-up logic with Clerk-backed account creation, email verification preparation, and loading-state UI.
Verification screens
apps/mobile/app/(auth)/verify.tsx, apps/mobile/app/(auth)/sign-in-verify.tsx
Adds code-entry verification screens for sign-up email verification and sign-in second-factor verification, with Clerk session activation and error/loading states.
Forgot password and home chrome
apps/mobile/app/(auth)/forgot-password.tsx, apps/mobile/app/(tabs)/home.tsx, apps/mobile/components/HomeHeader.tsx
Adds a forgot-password placeholder screen, removes the temporary home header action, and updates the home header layout and icon styling.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant SignInScreen
  participant Clerk
  participant Router

  User->>SignInScreen: submit email/password
  SignInScreen->>Clerk: signIn.create(identifier, password)
  Clerk-->>SignInScreen: complete, second factor, or error
  SignInScreen->>Clerk: setActive(session)
  SignInScreen->>Router: navigate to /(tabs)/home or /(auth)/sign-in-verify
Loading
sequenceDiagram
  participant User
  participant SignUpScreen
  participant Clerk
  participant Router
  participant VerifyScreen

  User->>SignUpScreen: submit name/email/password
  SignUpScreen->>Clerk: signUp.create(...)
  SignUpScreen->>Clerk: prepareEmailAddressVerification(email_code)
  SignUpScreen->>Router: navigate to /(auth)/verify
  User->>VerifyScreen: enter 6-digit code
  VerifyScreen->>Clerk: attemptEmailAddressVerification(code)
  Clerk-->>VerifyScreen: complete + createdSessionId
  VerifyScreen->>Clerk: setActive(session)
  VerifyScreen->>Router: navigate to /(tabs)/home
Loading

Possibly related PRs

  • OumB2021/Journal#3: Both PRs modify apps/mobile/app/_layout.tsx’s RootLayout, so the provider composition changes are directly related.
  • OumB2021/Journal#5: Both PRs affect apps/mobile/app/_layout.tsx provider composition, with overlapping layout-level changes.
  • OumB2021/Journal#6: Both PRs modify apps/mobile/components/HomeHeader.tsx, changing the same header component’s rendering and styling.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is related to the auth-focused changes, but it is too vague to clearly describe the main update. Rename it to a specific summary like 'Add Clerk auth flow and verification screens'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch authLogic

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
apps/mobile/app/(auth)/sign-in.tsx (1)

27-51: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Consider trimming the email before submitting.

Users frequently introduce leading/trailing whitespace (autocorrect, paste, keyboard suggestions). Passing an untrimmed identifier to signIn.create can cause avoidable sign-in failures.

♻️ Proposed tweak
-      const attempt = await signIn.create({ identifier: email, password });
+      const attempt = await signIn.create({ identifier: email.trim(), password });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/mobile/app/`(auth)/sign-in.tsx around lines 27 - 51, Trim the email
before calling signIn.create in handleSignIn so accidental leading or trailing
whitespace does not break sign-in. Update the identifier value used in the
create call to use the cleaned email while keeping the rest of the sign-in flow
in SignInScreen unchanged.
apps/mobile/app/(auth)/sign-up.tsx (1)

28-55: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Consider extracting the Clerk sign-up flow into a reusable hook.

The submit handler embeds auth business logic directly in the screen, and the Clerk error-handling block (isClerkAPIResponseError(err)err.errors[0]?.message ?? "Something went wrong.") is now duplicated across sign-in.tsx, sign-up.tsx, and verify.tsx. A small hooks/useAuthError (or useSignUpFlow) helper would keep these screens focused on routing/composition and remove the duplication.

As per coding guidelines: "In Expo Router screens under apps/mobile/app/, keep files focused on routing and screen composition only; do not put large reusable UI blocks or business logic here."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/mobile/app/`(auth)/sign-up.tsx around lines 28 - 55, The sign-up
screen’s handleCreateAccount in sign-up.tsx mixes reusable auth/business logic
with routing, and the Clerk error mapping is duplicated across sign-in, sign-up,
and verify. Extract the shared sign-up/auth error handling into a reusable hook
such as useAuthError or useSignUpFlow, then have handleCreateAccount focus on
form submission and navigation while reusing the centralized Clerk error
translation.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/mobile/app/_layout.tsx`:
- Around line 39-42: The ClerkProvider setup in _layout.tsx should not read
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY inline without validation. Create a local
publishableKey from the env var, check it before rendering ClerkProvider, and
throw a clear error when it is missing so misconfigured builds fail fast. Keep
the change focused around the ClerkProvider wrapper and its publishableKey prop.

In `@apps/mobile/lib/api.ts`:
- Around line 4-23: The useApi hook should add an abort/timeout path so requests
in the useCallback wrapper do not hang indefinitely, especially for
sign-in/sign-up/verify flows. Update the fetch logic to create and pass an
AbortController signal with a configurable timeout, and ensure the timeout is
cleared after completion. Also change the non-ok response handling in useApi so
it reads the response body from res before throwing and includes that backend
message in the thrown error instead of only the status code.

In `@apps/mobile/package.json`:
- Line 23: The dependency entry for expo-auth-session is pinned to a version
that may not match Expo SDK 54. Update the package.json dependency using the
Expo-managed install flow so the version stays aligned with SDK 54, and verify
the app’s dependency declaration for expo-auth-session reflects the compatible
Expo version rather than a fixed manual pin.

---

Nitpick comments:
In `@apps/mobile/app/`(auth)/sign-in.tsx:
- Around line 27-51: Trim the email before calling signIn.create in handleSignIn
so accidental leading or trailing whitespace does not break sign-in. Update the
identifier value used in the create call to use the cleaned email while keeping
the rest of the sign-in flow in SignInScreen unchanged.

In `@apps/mobile/app/`(auth)/sign-up.tsx:
- Around line 28-55: The sign-up screen’s handleCreateAccount in sign-up.tsx
mixes reusable auth/business logic with routing, and the Clerk error mapping is
duplicated across sign-in, sign-up, and verify. Extract the shared sign-up/auth
error handling into a reusable hook such as useAuthError or useSignUpFlow, then
have handleCreateAccount focus on form submission and navigation while reusing
the centralized Clerk error translation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4869bb05-ad39-4807-956b-87f199dd1f30

📥 Commits

Reviewing files that changed from the base of the PR and between 8260065 and 13ecbe2.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (9)
  • apps/mobile/app/(auth)/forgot-password.tsx
  • apps/mobile/app/(auth)/sign-in.tsx
  • apps/mobile/app/(auth)/sign-up.tsx
  • apps/mobile/app/(auth)/verify.tsx
  • apps/mobile/app/_layout.tsx
  • apps/mobile/app/index.tsx
  • apps/mobile/lib/api.ts
  • apps/mobile/lib/clerk.ts
  • apps/mobile/package.json

Comment thread apps/mobile/app/_layout.tsx Outdated
Comment thread apps/mobile/lib/api.ts
Comment thread apps/mobile/package.json

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
apps/mobile/app/(auth)/sign-in.tsx (2)

117-132: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add accessibilityState for the disabled submit button.

The button visually disables and swaps to a spinner while isSubmitting, but screen readers aren't told it's disabled/busy.

♿ Proposed fix
           <Pressable
             onPress={handleSignIn}
             disabled={isSubmitting}
             className="h-[52px] rounded-[5px] items-center justify-center bg-interactive-bg"
             style={({ pressed }) => ({ opacity: pressed || isSubmitting ? 0.85 : 1 })}
             accessibilityRole="button"
             accessibilityLabel="Sign in"
+            accessibilityState={{ disabled: isSubmitting, busy: isSubmitting }}
           >
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/mobile/app/`(auth)/sign-in.tsx around lines 117 - 132, The submit
control in sign-in should expose its disabled/busy state to assistive tech.
Update the Pressable in sign-in.tsx (the one using handleSignIn and
isSubmitting) to include accessibilityState reflecting disabled and busy while
submitting, and keep it in sync with the existing disabled prop and spinner
logic so screen readers know the button is unavailable during submission.

27-57: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting auth logic out of the routing screen.

handleSignIn embeds the full Clerk sign-in state machine (attempt creation, second-factor branching, error mapping) directly in an Expo Router screen. As per path instructions, apps/mobile/app/**/*.{ts,tsx}: "keep files focused on routing and screen composition only; do not put large reusable UI blocks or business logic here." Extracting this into a useSignInFlow-style hook would improve testability and keep the screen focused on composition, and would also make it easier to fix the second-factor strategy issue above in one shared place with sign-in-verify.tsx.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/mobile/app/`(auth)/sign-in.tsx around lines 27 - 57, The sign-in screen
is handling the full Clerk auth state machine inside the route component, which
should be moved out of the routing file. Extract the logic in handleSignIn from
sign-in.tsx into a reusable hook or auth service such as useSignInFlow, keeping
the screen focused on UI and navigation only. Preserve the existing branching
for complete and needs_second_factor, and centralize error mapping there so
sign-in and sign-in-verify can share the same flow.

Source: Path instructions

apps/mobile/app/(auth)/sign-in-verify.tsx (1)

90-97: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add accessibilityState for the disabled Verify button.

Same gap as the sign-in screen: no disabled/busy state exposed to assistive tech during submission.

♿ Proposed fix
           <Pressable
             onPress={handleVerify}
             disabled={isSubmitting}
             className="h-[52px] rounded-[5px] items-center justify-center bg-interactive-bg"
             style={({ pressed }) => ({ opacity: pressed || isSubmitting ? 0.85 : 1 })}
             accessibilityRole="button"
             accessibilityLabel="Verify code"
+            accessibilityState={{ disabled: isSubmitting, busy: isSubmitting }}
           >
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/mobile/app/`(auth)/sign-in-verify.tsx around lines 90 - 97, The Verify
Pressable in sign-in-verify.tsx exposes an accessibility label but not its
disabled/busy state during submission. Update the Pressable used for
handleVerify to include accessibilityState reflecting isSubmitting, so assistive
tech can announce when the button is disabled or busy. Keep the existing
disabled prop and style behavior in sync with the new accessibilityState.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/mobile/app/`(auth)/sign-in.tsx:
- Around line 39-47: The sign-in MFA flow is using the wrong Clerk APIs for
email-code verification. In the sign-in handler that branches on attempt.status,
replace the prepareSecondFactor path with Clerk’s email-code flow by calling
signIn.mfa.sendEmailCode() before navigating to the verify screen, and update
the verify screen to use signIn.mfa.verifyEmailCode({ code }) instead of
attemptSecondFactor. Keep the existing sign-in success and error handling around
the signIn and router logic, but ensure the email-code path is wired through
these mfa methods so the “needs_second_factor” case completes correctly.

---

Nitpick comments:
In `@apps/mobile/app/`(auth)/sign-in-verify.tsx:
- Around line 90-97: The Verify Pressable in sign-in-verify.tsx exposes an
accessibility label but not its disabled/busy state during submission. Update
the Pressable used for handleVerify to include accessibilityState reflecting
isSubmitting, so assistive tech can announce when the button is disabled or
busy. Keep the existing disabled prop and style behavior in sync with the new
accessibilityState.

In `@apps/mobile/app/`(auth)/sign-in.tsx:
- Around line 117-132: The submit control in sign-in should expose its
disabled/busy state to assistive tech. Update the Pressable in sign-in.tsx (the
one using handleSignIn and isSubmitting) to include accessibilityState
reflecting disabled and busy while submitting, and keep it in sync with the
existing disabled prop and spinner logic so screen readers know the button is
unavailable during submission.
- Around line 27-57: The sign-in screen is handling the full Clerk auth state
machine inside the route component, which should be moved out of the routing
file. Extract the logic in handleSignIn from sign-in.tsx into a reusable hook or
auth service such as useSignInFlow, keeping the screen focused on UI and
navigation only. Preserve the existing branching for complete and
needs_second_factor, and centralize error mapping there so sign-in and
sign-in-verify can share the same flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 50d0b5e3-d4fc-4bfb-8b12-4269c9896a91

📥 Commits

Reviewing files that changed from the base of the PR and between 7e7e90e and 2fc7af7.

📒 Files selected for processing (5)
  • apps/mobile/app/(auth)/sign-in-verify.tsx
  • apps/mobile/app/(auth)/sign-in.tsx
  • apps/mobile/app/(tabs)/home.tsx
  • apps/mobile/components/HomeHeader.tsx
  • package.json
💤 Files with no reviewable changes (1)
  • apps/mobile/app/(tabs)/home.tsx

Comment thread apps/mobile/app/(auth)/sign-in.tsx
@OumB2021
OumB2021 merged commit 1bb4087 into main Jul 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant