Skip to content

Redirect on Agent Profile for NGO and Volunteers#680

Merged
need4deed merged 4 commits into
developfrom
darrell/auth/ngo-vol-redirect-agent
Jun 16, 2026
Merged

Redirect on Agent Profile for NGO and Volunteers#680
need4deed merged 4 commits into
developfrom
darrell/auth/ngo-vol-redirect-agent

Conversation

@DarrellRoberts

Copy link
Copy Markdown
Collaborator

Description

Adds a redirect on /agent/[id] for users who aren't ADMIN or COORDINATOR

Related Issues

Closes #576 , cooicides with PR 641 which adds unclickable links and restricted-list views

Changes

To reproduce:

  1. Login as AGENT or VOLUNTEER
  2. Navigate to .../dashbaord/agents/1
  3. You should be redirected to .../dashboard/agents
  4. Change role as either ADMIN or COORDINATOR
  5. Navigate to .../dashbaord/agents/1
  6. You should not be redirected and will see profile

Screenshots / Demos

If UI-related, add before/after or GIFs.

Checklist

  • WITHIN THE SCOPE OF AN ISSUE; No unnecessary files included
  • Tests added/updated
  • Documentation updated
  • CI passes

@nadavosa nadavosa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic is correct and the server-side auth check is the right approach for the app router. One issue though: the redirect loses the language prefix.

redirect(`/dashboard/agents`);

Since this page is under [lang], it should be:

const { id, lang } = await params;
// ...
redirect(`/${lang}/dashboard/agents`);

Otherwise users hitting an agent profile URL in German (/de/dashboard/agents/123) get redirected to /dashboard/agents which would either 404 or land on the wrong language.

@nadavosa nadavosa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic is correct and the server-side auth check is the right approach for the app router. One issue though: the redirect loses the language prefix.

redirect(`/dashboard/agents`);

Since this page is under [lang], it should be:

const { id, lang } = await params;
// ...
redirect(`/${lang}/dashboard/agents`);

Otherwise users hitting an agent profile URL in German (/de/dashboard/agents/123) get redirected to /dashboard/agents which would either 404 or land on the wrong language.

@DarrellRoberts

Copy link
Copy Markdown
Collaborator Author

thanks @nadavosa !

I'm going to have to argue with the AI I'm afraid.

In the middleware we are tracking the locale via a cookie which automatically inserts the chosen locale if absent. Therefore, when you redirect, the middleware intercepts the request and inserts the preferred locale based on the cookie value (it changes when the user changes the language).

Adding the lang to the redirect actually causes a 404 error as it redirects to something like: /de/dashboard/agents/de/dashboard/agents (because of the middleware).

If you've experienced issues when manually testing it though, let me know

@need4deed need4deed merged commit ba4da8e into develop Jun 16, 2026
1 check passed
@need4deed need4deed deleted the darrell/auth/ngo-vol-redirect-agent branch June 16, 2026 16:21
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.

NGO + Volunteer view: Agent profiles — no access, list only

3 participants