Skip to content

test(react): verify redirect behavior in AuthProvider - #176

Merged
halvaradop merged 2 commits into
masterfrom
test/verify-redirect-behavior
Jun 3, 2026
Merged

test(react): verify redirect behavior in AuthProvider#176
halvaradop merged 2 commits into
masterfrom
test/verify-redirect-behavior

Conversation

@halvaradop

@halvaradop halvaradop commented Jun 3, 2026

Copy link
Copy Markdown
Member

Description

This pull request adds test coverage for redirect behavior across the AuthProvider implementations provided by @aura-stack/react and the React-based framework integrations built on top of it, including @aura-stack/next and @aura-stack/react-router.

The tests verify that authentication actions correctly invoke the configured redirect handler and that framework-specific navigation integrations behave as expected.

For Next.js, coverage includes both supported routing strategies:

  • App Router (recommended), using useRouter from next/navigation
  • Pages Router, using useRouter from next/router

For React Router, the tests verify integration with the useNavigate hook.

Note

This PR was introduced as a follow-up to the custom redirect support added in @aura-stack/react. The redirect functionality itself is not being modified in this PR; this update focuses exclusively on validating its behavior through automated tests.

Key Changes

  • Added tests for Next.js App Router integrations
  • Added tests for Next.js Pages Router integrations
  • Added tests for React Router integrations
  • Expanded test coverage across React-based packages
  • Added Vitest scripts:
    • test
    • test:watch
    • test:coverage

Related PRs

@vercel

vercel Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
auth Skipped Skipped Jun 3, 2026 3:08am

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@halvaradop, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 20 minutes and 26 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 75dc5672-9498-41b0-80f9-6210d4746070

📥 Commits

Reviewing files that changed from the base of the PR and between 47abab5 and 2b70684.

📒 Files selected for processing (17)
  • packages/next/package.json
  • packages/next/src/client.ts
  • packages/next/src/context.tsx
  • packages/next/src/pages/client.ts
  • packages/next/src/pages/context.tsx
  • packages/next/src/pages/index.ts
  • packages/next/test/app-router/api/getSession.test.ts
  • packages/next/test/app-router/api/signIn.test.ts
  • packages/next/test/app-router/api/signInCredentials.test.ts
  • packages/next/test/app-router/api/signOut.test.ts
  • packages/next/test/app-router/api/updateSession.test.ts
  • packages/next/test/app-router/client/context.test.tsx
  • packages/next/test/pages-router/client/context.test.tsx
  • packages/next/test/pages-router/handler.test.ts
  • packages/next/test/pages-router/preset.ts
  • packages/next/vitest.config.ts
  • packages/react-router/src/context.tsx
📝 Walkthrough

Walkthrough

This PR adds React Router integration for the auth provider by introducing a navigation-aware AuthProvider wrapper, establishing test infrastructure with Vitest, and providing comprehensive test coverage for both provider behavior and redirect flows.

Changes

React Router AuthProvider Integration

Layer / File(s) Summary
Test infrastructure setup
packages/react-router/vitest.config.ts, packages/react-router/tsconfig.json, packages/react-router/package.json, packages/react/package.json, pnpm-workspace.yaml
Vitest and jsdom environment configured with path aliases, npm test scripts added, TypeScript paths expanded to include test directory, and testing-library dependencies centralized in workspace catalog.
AuthProvider wrapper and exports
packages/react-router/src/context.tsx, packages/react-router/src/client.ts
React Router-specific AuthProvider component wraps the base provider from @aura-stack/react/context and defaults the redirect prop to a useNavigate-based navigation function; client.ts updated to re-export AuthProviderProps from the new local context module.
Provider rendering and prop forwarding tests
packages/react-router/test/context/provider.test.tsx
Tests verify that AuthProvider renders children, forwards custom redirect functions without calling navigate, provides a default redirect that calls navigate, and passes client and initialSession props unchanged to the inner provider.
Redirect integration tests
packages/react-router/test/context/redirect.test.tsx
Tests verify that signOut and OAuth signIn with redirect: true invoke either the custom provider-level redirect callback or fall back to navigate, and handle edge cases such as undefined redirect and unsuccessful sign-out with no redirect URL.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • aura-stack-ts/auth#175: Introduces AuthProviderProps.redirect support that this PR re-exports and wires into useNavigate for React Router navigation.
  • aura-stack-ts/auth#142: Initial setup of packages/react-router/src/client.ts re-exports; this PR refactors those exports to pull AuthProviderProps from the new local context module.

Poem

🐰 A provider hops through router's domain,
With useNavigate steering the lane,
Tests catch each redirect with glee,
From mock to flow, all wild and free!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'test(react): verify redirect behavior in AuthProvider' accurately describes the primary changes - adding comprehensive test coverage for redirect behavior in the AuthProvider component across the react-router package.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/verify-redirect-behavior

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@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: 2

🧹 Nitpick comments (1)
packages/react-router/test/context/provider.test.tsx (1)

86-112: 💤 Low value

Redundant tests overlap earlier cases.

calls navigate when no redirect prop is provided and redirect fn is invoked (Lines 86-96) duplicates wraps navigate as the built-in redirect... (Lines 56-66), and navigate is NOT called when a custom redirect prop overrides the built-in (Lines 98-112) is a strict subset of calls the custom redirect fn... (Lines 68-84). Consider folding the unique assertions (toHaveBeenCalledOnce) into the earlier tests and dropping the duplicates to reduce maintenance surface.

🤖 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 `@packages/react-router/test/context/provider.test.tsx` around lines 86 - 112,
Remove the two redundant tests ("calls navigate when no redirect prop is
provided and redirect fn is invoked" and "navigate is NOT called when a custom
redirect prop overrides the built-in") and fold their unique assertions into the
earlier tests: add the toHaveBeenCalledOnce() assertion into the existing "wraps
navigate as the built-in redirect..." test that renders <AuthProvider
client={mockClient}> and uses MockProvider.mock.calls[0][0].redirect to invoke
the built-in redirect, and ensure the "calls the custom redirect fn..." test
that passes redirect={customRedirect} asserts mockNavigate was not called; this
keeps AuthProvider, MockProvider.mock.calls access, mockNavigate checks and
customRedirect behavior while removing duplicate test cases.
🤖 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 `@packages/react-router/package.json`:
- Around line 15-17: Add the missing devDependencies for the Vitest tooling used
by the package.json scripts: declare "vitest" and "`@vitest/coverage-v8`" in this
package's devDependencies so the scripts "test", "test:watch", and
"test:coverage" can run in isolation; update the package.json devDependencies
block to pin the same versions used in the repo catalog and run install to
ensure the tooling is available for filtered/isolated test runs.

In `@packages/react-router/src/context.tsx`:
- Line 4: The wrapper currently defines const AuthProvider = ({ client,
children, initialSession, redirect }: AuthProviderProps) which drops the
generic; change it to declare the wrapper as AuthProvider<DefaultUser extends
User = User>(props: AuthProviderProps<DefaultUser>) (or const AuthProvider =
<DefaultUser extends User = User>(props: AuthProviderProps<DefaultUser>) => ...)
and forward those generic props to the upstream component as
<Provider<DefaultUser> ...> (preserving client, children, initialSession,
redirect). Also import User from '`@aura-stack/auth`' so the DefaultUser
constraint matches the base implementation.

---

Nitpick comments:
In `@packages/react-router/test/context/provider.test.tsx`:
- Around line 86-112: Remove the two redundant tests ("calls navigate when no
redirect prop is provided and redirect fn is invoked" and "navigate is NOT
called when a custom redirect prop overrides the built-in") and fold their
unique assertions into the earlier tests: add the toHaveBeenCalledOnce()
assertion into the existing "wraps navigate as the built-in redirect..." test
that renders <AuthProvider client={mockClient}> and uses
MockProvider.mock.calls[0][0].redirect to invoke the built-in redirect, and
ensure the "calls the custom redirect fn..." test that passes
redirect={customRedirect} asserts mockNavigate was not called; this keeps
AuthProvider, MockProvider.mock.calls access, mockNavigate checks and
customRedirect behavior while removing duplicate test cases.
🪄 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

Run ID: 8d2a8ba4-8d8f-4b20-b74e-d2522498e672

📥 Commits

Reviewing files that changed from the base of the PR and between 45fc929 and 47abab5.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • packages/react-router/package.json
  • packages/react-router/src/client.ts
  • packages/react-router/src/context.tsx
  • packages/react-router/test/context/provider.test.tsx
  • packages/react-router/test/context/redirect.test.tsx
  • packages/react-router/tsconfig.json
  • packages/react-router/vitest.config.ts
  • packages/react/package.json
  • pnpm-workspace.yaml

Comment thread packages/react-router/package.json
Comment thread packages/react-router/src/context.tsx Outdated
@halvaradop
halvaradop merged commit 43121f3 into master Jun 3, 2026
7 checks passed
@halvaradop
halvaradop deleted the test/verify-redirect-behavior branch June 3, 2026 03:15
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