Skip to content

[BUG] Broken Auth Redirect State and Route Guard Loop on Protected Resource Access #666

@shivani11jadhav

Description

@shivani11jadhav

Description

Currently, when an unauthenticated user tries to click on a restricted action inside the /courses or portal section (like tracking path progress or viewing locked content), the route guard intercepts the request but fails to preserve the initial destination state (intended target URL).

Instead of redirecting the user back to the exact course page they were viewing after a successful login, the application defaults back to the homepage (/). This ruins the user experience as they have to manually search for the course again.

Steps to Reproduce

  1. Log out of the platform (or use Incognito).
  2. Go directly to a specific course detail page or syllabus overview section.
  3. Click an action that triggers the authorization barrier (Login modal/page).
  4. Complete the sign-in/auth flow successfully.
  5. Notice that you are dropped on the main root landing page (/) instead of being seamlessly redirected back to the course page you intended to explore.

Technical Analysis & Solution

The current authentication hook/middleware is just calling router.push('/') upon a successful login event without checking for an active callback or redirectTo parameter inside the state/query strings.

  • Fix: Intercept the initial route path using Next.js routing query string (e.g., /login?callbackUrl=/courses/nextjs-deep-dive).
  • Result: After authentication finishes, dynamically parse the callbackUrl search param and route the user seamlessly back to their intended dashboard, establishing standard enterprise-grade route guarding.

Please assign this to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gssoc26This is a official GirlScript Summer of Code label.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions