Skip to content

fix: redirect on /agent/[id] #695

@DarrellRoberts

Description

@DarrellRoberts

Summary

On production and staging when the agent/:id redirect was live, the user even if they were Coordinator or Admin would be redirected and unable to access the profile.

Steps to Reproduce

  1. Paste the following in src/app/[lang]/dashboard/agents/[id]/page.tsx
import ProfileLayout from "@/components/Dashboard/Profile/ProfileLayout";
import { getServerUserRole } from "@/hooks/api/getUserRole";
import { RouteParams } from "@/types";
import { UserRole } from "need4deed-sdk";
import { cookies } from "next/headers";
import { redirect } from "next/navigation";

export default async function DashboardAgentPage({ params }: RouteParams) {
  const { id } = await params;

  const cookieStore = await cookies();
  const cookieHeader = cookieStore.toString();
  const userRole = await getServerUserRole(cookieHeader);

  if (!userRole || (userRole !== UserRole.COORDINATOR && userRole !== UserRole.ADMIN)) {
    redirect(`/dashboard/agents`);
  }
  return <ProfileLayout entityId={id} entityType="agent" />;
}
  1. Change role of account to either COORDINATOR or ADMIN (if not already)
  2. Navigate to an agent profile
  3. Observe redirect

Expected Behavior

If user is COORDINATOR or ADMIN, there should be no redirect

If user is AGENT or VOLUNTEER, there should be a redirect

Actual Behavior

local dev

If user is COORDINATOR or ADMIN, there is no redirect

If user is AGENT or VOLUNTEER, there is a redirect

staging

If user is COORDINATOR or ADMIN, there is a redirect

If user is AGENT or VOLUNTEER, there is a redirect

production

If user is COORDINATOR or ADMIN, there is a redirect

If user is AGENT or VOLUNTEER, there is a redirect

Environment

Incorrect redirect was recorded on:

  • Firefox, ubuntu

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions