Ver código fonte

update authoption

production_process
MSI\derek 2 meses atrás
pai
commit
a9b818aa6f
2 arquivos alterados com 7 adições e 6 exclusões
  1. +4
    -4
      src/app/(main)/layout.tsx
  2. +3
    -2
      src/config/authConfig.ts

+ 4
- 4
src/app/(main)/layout.tsx Ver arquivo

@@ -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, SessionWithTokens>(authOptions);

if (!session?.user) {
redirect("/login");
}

if (session) {
SetupAxiosInterceptors(session?.accessToken);
SetupAxiosInterceptors(session.accessToken);
}

return (


+ 3
- 2
src/config/authConfig.ts Ver arquivo

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


Carregando…
Cancelar
Salvar