Skip to content

Commit

Permalink
[TM-1489] redirect funder and governmet roles to dashboard learn more…
Browse files Browse the repository at this point in the history
… page
  • Loading branch information
cesarLima1 committed Nov 19, 2024
1 parent 5e027e3 commit 47f5569
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/middleware.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,21 @@ export async function middleware(request: NextRequest) {
const userIsAdmin = isAdmin(user?.primaryRole as UserRole);
const userIsFunderOrGovernment = user?.primaryRole === "funder" || user?.primaryRole === "government";

// Allow admin and funder/government users to access dashboard routes
if ((userIsAdmin || userIsFunderOrGovernment) && request.nextUrl.pathname.startsWith("/dashboard")) {
// Redirect funder/government users to /dashboard/learn-more?tab=about-us
if (userIsFunderOrGovernment) {
matcher.redirect(`/dashboard/learn-more?tab=about-us`, { cacheResponse: true });
return matcher.getResult();
}

// Allow admin users to access dashboard routes
if (userIsAdmin && request.nextUrl.pathname.startsWith("/dashboard")) {
matcher.next();
return matcher.getResult();
}

// Default admin redirect for non-dashboard routes
matcher.when(user != null && userIsAdmin)?.redirect(`/admin`, { cacheResponse: true });

// Special handling for funder and government roles
if (userIsFunderOrGovernment) {
// Redirect funder/government directly to dashboard regardless of organization
matcher.redirect(`/dashboard`, { cacheResponse: true });
return matcher.getResult();
}

matcher
.when(organisation != null && organisation.status !== "draft")
?.startWith("/organization/create")
Expand Down

0 comments on commit 47f5569

Please sign in to comment.