Skip to content

feat(auth): auto-redirect after authentication#212

Merged
zainfathoni merged 4 commits intostagingfrom
feat/rb-logic.1-auto-redirect-after-auth
Feb 1, 2026
Merged

feat(auth): auto-redirect after authentication#212
zainfathoni merged 4 commits intostagingfrom
feat/rb-logic.1-auto-redirect-after-auth

Conversation

@zainfathoni
Copy link
Copy Markdown
Owner

@zainfathoni zainfathoni commented Feb 1, 2026

Summary

Implements auto-redirect after authentication and consistent permission redirects for the dashboard.

Changes

Auto-redirect after authentication (rb-logic.1)

  • login.tsx: Read redirectTo from URL params, store in session, preserve through magic link flow
  • magic.tsx: Read redirectTo from session and redirect there after successful auth

Permission redirects (rb-logic.2)

  • Add missing permission check in dashboard.transactions.$transactionId.$action loader
  • Standardize all permission redirects to /dashboard instead of inconsistent paths
  • Add comprehensive unit tests for permission functions
  • Add E2E tests for permission redirect behavior

Flow

  1. User visits /dashboard/courses (protected)
  2. requireUser redirects to /login?redirectTo=/dashboard/courses
  3. Login page stores redirectTo in session and sends magic link
  4. User clicks magic link → /magic reads session and redirects to /dashboard/courses
  5. If user lacks permission for a route, they're redirected to /dashboard

Tests

  • Unit tests for redirect URL construction and preservation
  • Unit tests for permission functions
  • E2E tests for unauthenticated/authenticated redirect flows
  • E2E tests for permission redirect behavior

Reference

Based on: zainfathoni/remix-jokes@a931d94

Closes rb-logic.1, rb-logic.2

zainfathoni and others added 2 commits February 1, 2026 12:43
When a user tries to access a protected route without being authenticated,
the original URL is saved in session and they are redirected back after
successful magic link login.

Closes rb-logic.1

Amp-Thread-ID: https://ampcode.com/threads/T-019c17af-6967-74be-8e42-6191059b8d63
Co-authored-by: Amp <amp@ampcode.com>
- Unit tests for redirect URL construction and preservation
- E2E tests for unauthenticated redirect flow and authenticated redirect

Amp-Thread-ID: https://ampcode.com/threads/T-019c17af-6967-74be-8e42-6191059b8d63
Co-authored-by: Amp <amp@ampcode.com>
kodiakhq[bot]
kodiakhq Bot previously approved these changes Feb 1, 2026
- Add permission check in dashboard.transactions.$transactionId.$action loader
- Standardize all permission redirects to /dashboard instead of various paths
- Add comprehensive unit tests for permission functions
- Add E2E tests for permission redirect behavior

Closes rb-logic.2

Amp-Thread-ID: https://ampcode.com/threads/T-019c17de-be40-76a8-a962-78347f08fdda
Co-authored-by: Amp <amp@ampcode.com>
kodiakhq[bot]
kodiakhq Bot previously approved these changes Feb 1, 2026
The permission-redirect.spec.ts tests use authFixtures.admin,
but the global setup was not generating admin.local.json.

This caused all Admin role tests to fail in CI with:
'ENOENT: no such file or directory, open e2e/fixtures/auth/admin.local.json'
@zainfathoni zainfathoni merged commit 21a9d54 into staging Feb 1, 2026
12 of 13 checks passed
@zainfathoni zainfathoni deleted the feat/rb-logic.1-auto-redirect-after-auth branch February 1, 2026 10:14
zainfathoni added a commit that referenced this pull request Feb 10, 2026
* feat(auth): auto-redirect after authentication

When a user tries to access a protected route without being authenticated,
the original URL is saved in session and they are redirected back after
successful magic link login.

Closes rb-logic.1

Amp-Thread-ID: https://ampcode.com/threads/T-019c17af-6967-74be-8e42-6191059b8d63


* test(auth): add unit and e2e tests for auto-redirect

- Unit tests for redirect URL construction and preservation
- E2E tests for unauthenticated redirect flow and authenticated redirect

Amp-Thread-ID: https://ampcode.com/threads/T-019c17af-6967-74be-8e42-6191059b8d63


* feat(auth): redirect to dashboard for insufficient permissions

- Add permission check in dashboard.transactions.$transactionId.$action loader
- Standardize all permission redirects to /dashboard instead of various paths
- Add comprehensive unit tests for permission functions
- Add E2E tests for permission redirect behavior

Closes rb-logic.2

Amp-Thread-ID: https://ampcode.com/threads/T-019c17de-be40-76a8-a962-78347f08fdda


* fix(e2e): add admin fixture to global setup

The permission-redirect.spec.ts tests use authFixtures.admin,
but the global setup was not generating admin.local.json.

This caused all Admin role tests to fail in CI with:
'ENOENT: no such file or directory, open e2e/fixtures/auth/admin.local.json'

---------

Co-authored-by: Zain Fathoni <me@zainf.dev>
Co-authored-by: Amp <amp@ampcode.com>
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