From a9b818aa6f687a9a480e40400e36d07ab562a49c Mon Sep 17 00:00:00 2001 From: "MSI\\derek" Date: Wed, 11 Jun 2025 14:28:08 +0800 Subject: [PATCH] update authoption --- src/app/(main)/layout.tsx | 8 ++++---- src/config/authConfig.ts | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/(main)/layout.tsx b/src/app/(main)/layout.tsx index e073b45..cdc4905 100644 --- a/src/app/(main)/layout.tsx +++ b/src/app/(main)/layout.tsx @@ -1,6 +1,6 @@ import AppBar from "@/components/AppBar"; -import { getServerSession } from "next-auth"; -import { authOptions } from "@/config/authConfig"; +import { AuthOptions, getServerSession } from "next-auth"; +import { authOptions, SessionWithTokens } from "@/config/authConfig"; import { redirect } from "next/navigation"; import Box from "@mui/material/Box"; import { NAVIGATION_CONTENT_WIDTH } from "@/config/uiConfig"; @@ -16,14 +16,14 @@ export default async function MainLayout({ }: { children: React.ReactNode; }) { - const session = await getServerSession(authOptions); + const session = await getServerSession(authOptions); if (!session?.user) { redirect("/login"); } if (session) { - SetupAxiosInterceptors(session?.accessToken); + SetupAxiosInterceptors(session.accessToken); } return ( diff --git a/src/config/authConfig.ts b/src/config/authConfig.ts index 125f569..335d375 100644 --- a/src/config/authConfig.ts +++ b/src/config/authConfig.ts @@ -3,11 +3,12 @@ import CredentialsProvider from "next-auth/providers/credentials"; import { LOGIN_API_PATH } from "./api"; export interface SessionWithTokens extends Session { - accessToken?: string; + accessToken: string | null; refreshToken?: string; abilities: string[] } + export const authOptions: AuthOptions = { debug: process.env.NODE_ENV === "development", providers: [ @@ -49,7 +50,7 @@ export const authOptions: AuthOptions = { const sessionWithToken: SessionWithTokens = { ...session, // Add the data from the token to the session - accessToken: token.accessToken as string | undefined, + accessToken: token.accessToken as string | null, refreshToken: token.refreshToken as string | undefined, abilities: token.abilities as string[] };