Skip to content

Commit

Permalink
feat: implement authGuard for staff role validation in dashboard routes
Browse files Browse the repository at this point in the history
  • Loading branch information
tigawanna committed Jan 1, 2025
1 parent 45f86f8 commit bc84b64
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/lib/tanstack/query/use-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ export async function authGuard({ ctx, role, reverse }: AuthGuardProps) {
});
}
// redirect if not the right role
// if (role && user?.record?.role !== role) {
// if (!(role && role==="staff" && user?.record?.staff?.length > 0)) {
// // console.log(" ++++++++ user exists but wrong role redirecting back ++++++ ");
// throw redirect({
// to: returnTo ?? "/",
// to:".."
// });
// }
// console.log(" ++++++++ fall through case user exists ++++++ ");
Expand Down
5 changes: 5 additions & 0 deletions src/routes/dashboard/staff/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { createFileRoute } from "@tanstack/react-router";
import { z } from "zod";
import { StaffPage } from "./-components/StaffPage";
import { authGuard } from "@/lib/tanstack/query/use-viewer";

const searchparams = z.object({
sq: z.string().optional(),
});

export const Route = createFileRoute("/dashboard/staff/")({
validateSearch: (search) => searchparams.parse(search),
async beforeLoad(ctx) {
const context = ctx as any
await authGuard({ ctx:context });
},
component:StaffPage
});
4 changes: 2 additions & 2 deletions src/routes/dashboard/tenants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const Route = createFileRoute("/dashboard/tenants/")({
component: TenantsPage,
validateSearch: (search) => searchparams.parse(search),
async beforeLoad(ctx) {
// @ts-expect-error
await authGuard({ ctx });
const context = ctx as any;
await authGuard({ ctx: context,role:"staff" });
},
});

0 comments on commit bc84b64

Please sign in to comment.