Browse Source

Modify Session Type

production_process
MSI\2Fi 2 months ago
parent
commit
bb96d8b1e2
3 changed files with 22 additions and 2 deletions
  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 View File

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


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


const { data: session } = useSession();

useEffect(() => { useEffect(() => {
const completedList = entries.filter((e) => e.status === "completed"); const completedList = entries.filter((e) => e.status === "completed");
const processedQty = completedList.reduce( const processedQty = completedList.reduce(
@@ -475,7 +478,8 @@ function PoInputGrid({
disabled={ disabled={
stockInLineStatusMap[status] === 9 || stockInLineStatusMap[status] === 9 ||
stockInLineStatusMap[status] <= 2 || 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 // set _isNew to false after posting
// or check status // or check status


+ 3
- 1
src/config/authConfig.ts View File

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


const user = await res.json(); const user = await res.json();


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


+ 14
- 0
types/next-auth.d.ts View File

@@ -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;
}
}

Loading…
Cancel
Save