mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-02 03:38:22 +00:00
feat: add admin check for device and payment pages; update session type to include is_admin property ✨
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 8m9s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 8m9s
This commit is contained in:
@ -3,6 +3,7 @@ import { DevicesTable } from "@/components/devices-table";
|
||||
import Search from "@/components/search";
|
||||
import AddDeviceDialogForm from "@/components/user/add-device-dialog";
|
||||
import { getServerSession } from "next-auth";
|
||||
import { redirect } from "next/navigation";
|
||||
import React, { Suspense } from "react";
|
||||
import DevicesTableSkeleton from "./device-table-skeleton";
|
||||
|
||||
@ -17,6 +18,7 @@ export default async function Devices({
|
||||
const query = (await searchParams)?.query || "";
|
||||
const page = (await searchParams)?.page || 1;
|
||||
const session = await getServerSession(authOptions);
|
||||
if (session?.user?.is_admin) return redirect("/user-devices");
|
||||
return (
|
||||
<div>
|
||||
<div className="flex justify-between items-center border-[1px] rounded-md border-dashed font-bold title-bg py-4 px-2 mb-4">
|
||||
|
@ -1,8 +1,11 @@
|
||||
import { authOptions } from "@/app/auth";
|
||||
import { PaymentsTable } from "@/components/payments-table";
|
||||
import Search from "@/components/search";
|
||||
import { getServerSession } from "next-auth";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Suspense } from "react";
|
||||
|
||||
export default async function Devices({
|
||||
export default async function Payments({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{
|
||||
@ -13,6 +16,10 @@ export default async function Devices({
|
||||
}>;
|
||||
}) {
|
||||
const query = (await searchParams)?.query || "";
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.is_admin) {
|
||||
return redirect("/user-payments");
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<div className="flex justify-between items-center border-[1px] rounded-md border-dashed font-bold title-bg py-4 px-2 mb-4">
|
||||
|
1
app/next-auth.d.ts
vendored
1
app/next-auth.d.ts
vendored
@ -25,6 +25,7 @@ declare module "next-auth" {
|
||||
last_login?: string;
|
||||
date_joined?: string;
|
||||
is_superuser?: boolean;
|
||||
is_admin?: boolean;
|
||||
};
|
||||
expires: ISODateString;
|
||||
}
|
||||
|
Reference in New Issue
Block a user