Explorar el Código

Modify Session Type

production_process
MSI\2Fi hace 2 meses
padre
commit
bb96d8b1e2
Se han modificado 3 ficheros con 22 adiciones y 2 borrados
  1. +5
    -1
      src/components/PoDetail/PoInputGrid.tsx
  2. +3
    -1
      src/config/authConfig.ts
  3. +14
    -0
      types/next-auth.d.ts

+ 5
- 1
src/components/PoDetail/PoInputGrid.tsx Ver fichero

@@ -56,6 +56,7 @@ import { fetchPoQrcode } from "@/app/api/pdf/actions";
import { fetchQcResult } from "@/app/api/qc/actions";
import PoQcStockInModal from "./PoQcStockInModal"
import DoDisturbIcon from "@mui/icons-material/DoDisturb";
import { useSession } from "next-auth/react";

interface ResultWithId {
id: number;
@@ -135,6 +136,8 @@ function PoInputGrid({
return total;
});

const { data: session } = useSession();

useEffect(() => {
const completedList = entries.filter((e) => e.status === "completed");
const processedQty = completedList.reduce(
@@ -475,7 +478,8 @@ function PoInputGrid({
disabled={
stockInLineStatusMap[status] === 9 ||
stockInLineStatusMap[status] <= 2 ||
stockInLineStatusMap[status] >= 7
stockInLineStatusMap[status] >= 7 ||
(!session?.user?.abilities?.includes("APPROVAL") && stockInLineStatusMap[status] >= 3 && stockInLineStatusMap[status] <= 5)
}
// set _isNew to false after posting
// or check status


+ 3
- 1
src/config/authConfig.ts Ver fichero

@@ -28,7 +28,6 @@ export const authOptions: AuthOptions = {
});

const user = await res.json();

if (res.ok && user) {
return user;
@@ -56,6 +55,9 @@ export const authOptions: AuthOptions = {
refreshToken: token.refreshToken as string | undefined,
abilities: token.abilities as string[]
};
if (sessionWithToken.user) {
sessionWithToken.user.abilities = token.abilities as string[];
}
return sessionWithToken;
},
},


+ 14
- 0
types/next-auth.d.ts Ver fichero

@@ -0,0 +1,14 @@
// types/next-auth.d.ts
import NextAuth from "next-auth";

declare module "next-auth" {
interface Session {
user?: {
name?: string | null;
email?: string | null;
image?: string | null;
abilities?: string[] | null; // <-- Add your custom fields here
};
expires: ISODateString;
}
}

Cargando…
Cancelar
Guardar