-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Labels
authTasks related to authentication and user managementTasks related to authentication and user managementbugSomething isn't workingSomething isn't workingfix
Description
Currently, when a non-logged-in user tries to access a protected route, the middleware correctly redirects them to /login?next=/original-path. However, the login process ignores this next parameter and always redirects the user to /dashboard upon successful authentication.
Problem Locations:
src/app/(auth)/login/page.tsx: If a user is already logged in and hits the login page with anextparameter, they are redirected to/dashboardinstead of thenextdestination.src/app/(auth)/login/login-form.tsx: Needs to capture thenextsearch parameter from the URL and include it in the form (e.g., as a hidden input).src/app/(auth)/actions.ts(loginAction): Needs to check for thenextparameter informDataand redirect to it instead of/dashboardif present.
Proposed Solution:
- Update
LoginPageto readnextfrom search params (if possible, though Server Components get params via props). - Update
LoginFormto readnextfromuseSearchParamsor props. - Add
<input type="hidden" name="next" value={next} />to the form. - Update
loginActionto:const next = formData.get("next") as string | null; redirect(next ?? "/dashboard");
Copilot
Metadata
Metadata
Assignees
Labels
authTasks related to authentication and user managementTasks related to authentication and user managementbugSomething isn't workingSomething isn't workingfix