@@ -1,6 +1,6 @@ | |||||
import AppBar from "@/components/AppBar"; | 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 { redirect } from "next/navigation"; | ||||
import Box from "@mui/material/Box"; | import Box from "@mui/material/Box"; | ||||
import { NAVIGATION_CONTENT_WIDTH } from "@/config/uiConfig"; | import { NAVIGATION_CONTENT_WIDTH } from "@/config/uiConfig"; | ||||
@@ -16,14 +16,14 @@ export default async function MainLayout({ | |||||
}: { | }: { | ||||
children: React.ReactNode; | children: React.ReactNode; | ||||
}) { | }) { | ||||
const session = await getServerSession(authOptions); | |||||
const session = await getServerSession<AuthOptions, SessionWithTokens>(authOptions); | |||||
if (!session?.user) { | if (!session?.user) { | ||||
redirect("/login"); | redirect("/login"); | ||||
} | } | ||||
if (session) { | if (session) { | ||||
SetupAxiosInterceptors(session?.accessToken); | |||||
SetupAxiosInterceptors(session.accessToken); | |||||
} | } | ||||
return ( | return ( | ||||
@@ -3,11 +3,12 @@ import CredentialsProvider from "next-auth/providers/credentials"; | |||||
import { LOGIN_API_PATH } from "./api"; | import { LOGIN_API_PATH } from "./api"; | ||||
export interface SessionWithTokens extends Session { | export interface SessionWithTokens extends Session { | ||||
accessToken?: string; | |||||
accessToken: string | null; | |||||
refreshToken?: string; | refreshToken?: string; | ||||
abilities: string[] | abilities: string[] | ||||
} | } | ||||
export const authOptions: AuthOptions = { | export const authOptions: AuthOptions = { | ||||
debug: process.env.NODE_ENV === "development", | debug: process.env.NODE_ENV === "development", | ||||
providers: [ | providers: [ | ||||
@@ -49,7 +50,7 @@ export const authOptions: AuthOptions = { | |||||
const sessionWithToken: SessionWithTokens = { | const sessionWithToken: SessionWithTokens = { | ||||
...session, | ...session, | ||||
// Add the data from the token to the 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, | refreshToken: token.refreshToken as string | undefined, | ||||
abilities: token.abilities as string[] | abilities: token.abilities as string[] | ||||
}; | }; | ||||