Skip to content

feat: authgard - #19

Merged
OumB2021 merged 2 commits into
mainfrom
auth_gard
Jul 4, 2026
Merged

feat: authgard#19
OumB2021 merged 2 commits into
mainfrom
auth_gard

Conversation

@OumB2021

@OumB2021 OumB2021 commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Updated mobile app navigation to be consistently gated by authentication state, routing signed-in users to the main area and signed-out users to the sign-in flow.
    • Added a shared authentication gate to prevent the main navigators from rendering until auth status is fully resolved.
    • Introduced a dedicated loading state to avoid premature screen display during auth restoration.

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Mobile route entry points now share a common auth gate hook. The root, auth, and tabs layouts delegate redirect decisions to useAuthGate, which returns null, a redirect, or undefined based on Clerk auth state and configured targets.

Changes

Shared auth gating for mobile routing

Layer / File(s) Summary
Auth gate hook
apps/mobile/hooks/useAuthGate.tsx
Adds AuthGateOptions with optional signed-in and signed-out redirect targets, and implements useAuthGate on top of Clerk auth state.
Route layouts use the gate
apps/mobile/app/index.tsx, apps/mobile/app/(auth)/_layout.tsx, apps/mobile/app/(tabs)/_layout.tsx
Replaces direct auth checks and redirects in the root, auth, and tabs layouts with useAuthGate, and keeps navigator rendering behind the gate result.

Estimated code review effort: 2 (Simple) | ~12 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Root
  participant AuthLayout
  participant TabsLayout
  participant useAuthGate

  User->>Root: open app
  Root->>useAuthGate: redirectIfSignedIn / redirectIfSignedOut
  useAuthGate-->>Root: null, Redirect, or undefined
  alt gate returns Redirect
    Root-->>User: redirect
  else gate returns undefined
    Root-->>User: render root content
  end

  User->>AuthLayout: open auth route
  AuthLayout->>useAuthGate: redirectIfSignedIn "/(tabs)/home"
  useAuthGate-->>AuthLayout: null, Redirect, or undefined
  alt gate returns Redirect
    AuthLayout-->>User: redirect to /(tabs)/home
  else gate returns undefined
    AuthLayout-->>User: render Stack
  end

  User->>TabsLayout: open tabs route
  TabsLayout->>useAuthGate: redirectIfSignedOut "/(auth)/sign-in"
  useAuthGate-->>TabsLayout: null, Redirect, or undefined
  alt gate returns Redirect
    TabsLayout-->>User: redirect to /(auth)/sign-in
  else gate returns undefined
    TabsLayout-->>User: render Tabs
  end
Loading

Possibly related PRs

  • OumB2021/Journal#4: Modifies apps/mobile/app/(tabs)/_layout.tsx, which is also updated here to use the shared auth gate.
  • OumB2021/Journal#9: Touches apps/mobile/app/(auth)/_layout.tsx, the same auth route layout updated here for gate-based redirect handling.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is related to the auth gating changes, but the typo makes it unclear and not very descriptive. Rename it to something specific like "feat: add shared auth gate for mobile routes".
✅ 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 auth_gard

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.

🧹 Nitpick comments (1)
apps/mobile/app/(tabs)/_layout.tsx (1)

6-11: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider extracting the auth-gating boilerplate.

The isLoaded/isSignedIn gate here duplicates the same shape in apps/mobile/app/(auth)/_layout.tsx and apps/mobile/app/index.tsx. A small shared hook (e.g. useAuthGate) returning a redirect element or null would reduce triplication as more route groups are added.

🤖 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/`(tabs)/_layout.tsx around lines 6 - 11, The auth-loading and
sign-in redirect logic in TabsLayout is duplicated in other route entry points,
so extract it into a shared hook such as useAuthGate that returns either a
Redirect element or null. Update TabsLayout to delegate the isLoaded/isSignedIn
handling to that shared helper, and reuse the same hook from the auth layout and
app index so the auth-gating pattern stays centralized as more routes are added.
🤖 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.

Nitpick comments:
In `@apps/mobile/app/`(tabs)/_layout.tsx:
- Around line 6-11: The auth-loading and sign-in redirect logic in TabsLayout is
duplicated in other route entry points, so extract it into a shared hook such as
useAuthGate that returns either a Redirect element or null. Update TabsLayout to
delegate the isLoaded/isSignedIn handling to that shared helper, and reuse the
same hook from the auth layout and app index so the auth-gating pattern stays
centralized as more routes are added.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: be3594d8-e012-4195-a429-06cfcc9eb7ab

📥 Commits

Reviewing files that changed from the base of the PR and between 1bb4087 and 800f709.

📒 Files selected for processing (2)
  • apps/mobile/app/(auth)/_layout.tsx
  • apps/mobile/app/(tabs)/_layout.tsx

@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.

🧹 Nitpick comments (1)
apps/mobile/app/index.tsx (1)

5-6: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting route targets to a shared constant.

"/(tabs)/home" and "/(auth)/sign-in" are repeated as literals here and in (auth)/_layout.tsx / (tabs)/_layout.tsx. Centralizing them (e.g. a small routes.ts constants module) avoids drift if a route path is ever renamed.

♻️ Example extraction
+// apps/mobile/constants/routes.ts
+export const ROUTES = {
+  tabsHome: "/(tabs)/home",
+  authSignIn: "/(auth)/sign-in",
+} as const;
+import { ROUTES } from "`@/constants/routes`";
 const gate = useAuthGate({
-    redirectIfSignedIn: "/(tabs)/home",
-    redirectIfSignedOut: "/(auth)/sign-in",
+    redirectIfSignedIn: ROUTES.tabsHome,
+    redirectIfSignedOut: ROUTES.authSignIn,
 });
🤖 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/index.tsx` around lines 5 - 6, The redirect targets in the
app entry and layout files are duplicated string literals, so centralize them
into a shared routes constants module. Update the values used by the app
redirect config and the `(auth)/_layout.tsx` and `(tabs)/_layout.tsx` consumers
to import the same symbols instead of hardcoding `"/(tabs)/home"` and
`"/(auth)/sign-in"`, so route changes stay in sync.
🤖 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.

Nitpick comments:
In `@apps/mobile/app/index.tsx`:
- Around line 5-6: The redirect targets in the app entry and layout files are
duplicated string literals, so centralize them into a shared routes constants
module. Update the values used by the app redirect config and the
`(auth)/_layout.tsx` and `(tabs)/_layout.tsx` consumers to import the same
symbols instead of hardcoding `"/(tabs)/home"` and `"/(auth)/sign-in"`, so route
changes stay in sync.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a9768fc-a506-43de-9947-adaee7f71628

📥 Commits

Reviewing files that changed from the base of the PR and between 800f709 and f1d9a40.

📒 Files selected for processing (4)
  • apps/mobile/app/(auth)/_layout.tsx
  • apps/mobile/app/(tabs)/_layout.tsx
  • apps/mobile/app/index.tsx
  • apps/mobile/hooks/useAuthGate.tsx
✅ Files skipped from review due to trivial changes (1)
  • apps/mobile/hooks/useAuthGate.tsx

@OumB2021
OumB2021 merged commit 1bfd647 into main Jul 4, 2026
4 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