mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-08 19:16:37 +08:00
Fix next auth routes
This commit is contained in:
parent
3942f511cf
commit
7d6496a727
@ -1,41 +1,5 @@
|
|||||||
import NextAuth, { getServerSession, type NextAuthOptions } from "next-auth";
|
import { authOptions } from "@/app/auth";
|
||||||
import AzureADProvider from "next-auth/providers/azure-ad";
|
import NextAuth from "next-auth";
|
||||||
|
|
||||||
/**
|
|
||||||
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
|
|
||||||
*
|
|
||||||
* @see https://next-auth.js.org/configuration/options
|
|
||||||
*/
|
|
||||||
export const authOptions: NextAuthOptions = {
|
|
||||||
callbacks: {
|
|
||||||
session: ({ session, token }) => ({
|
|
||||||
...session,
|
|
||||||
user: {
|
|
||||||
...session.user,
|
|
||||||
id: token.sub,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
providers: [
|
|
||||||
AzureADProvider({
|
|
||||||
clientId: process.env.AZURE_AD_CLIENT_ID ?? "",
|
|
||||||
clientSecret: process.env.AZURE_AD_CLIENT_SECRET ?? "",
|
|
||||||
tenantId: process.env.AZURE_AD_TENANT_ID ?? "",
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
pages: {
|
|
||||||
signIn: "/login",
|
|
||||||
signOut: "/login",
|
|
||||||
error: "/login",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
|
|
||||||
*
|
|
||||||
* @see https://next-auth.js.org/configuration/nextjs
|
|
||||||
*/
|
|
||||||
export const getServerAuthSession = () => getServerSession(authOptions);
|
|
||||||
|
|
||||||
const handler = NextAuth(authOptions);
|
const handler = NextAuth(authOptions);
|
||||||
|
|
||||||
|
63
app/auth.ts
Normal file
63
app/auth.ts
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import {
|
||||||
|
getServerSession,
|
||||||
|
type DefaultSession,
|
||||||
|
type NextAuthOptions,
|
||||||
|
} from "next-auth";
|
||||||
|
import AzureADProvider from "next-auth/providers/azure-ad";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
|
||||||
|
* object and keep type safety.
|
||||||
|
*
|
||||||
|
* @see https://next-auth.js.org/getting-started/typescript#module-augmentation
|
||||||
|
*/
|
||||||
|
declare module "next-auth" {
|
||||||
|
interface Session extends DefaultSession {
|
||||||
|
user: {
|
||||||
|
id: string;
|
||||||
|
// ...other properties
|
||||||
|
// role: UserRole;
|
||||||
|
} & DefaultSession["user"];
|
||||||
|
}
|
||||||
|
|
||||||
|
// interface User {
|
||||||
|
// // ...other properties
|
||||||
|
// // role: UserRole;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
|
||||||
|
*
|
||||||
|
* @see https://next-auth.js.org/configuration/options
|
||||||
|
*/
|
||||||
|
export const authOptions: NextAuthOptions = {
|
||||||
|
callbacks: {
|
||||||
|
session: ({ session, token }) => ({
|
||||||
|
...session,
|
||||||
|
user: {
|
||||||
|
...session.user,
|
||||||
|
id: token.sub,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
providers: [
|
||||||
|
AzureADProvider({
|
||||||
|
clientId: process.env.AZURE_AD_CLIENT_ID ?? "",
|
||||||
|
clientSecret: process.env.AZURE_AD_CLIENT_SECRET ?? "",
|
||||||
|
tenantId: process.env.AZURE_AD_TENANT_ID ?? "",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
pages: {
|
||||||
|
signIn: "/login",
|
||||||
|
signOut: "/login",
|
||||||
|
error: "/login",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
|
||||||
|
*
|
||||||
|
* @see https://next-auth.js.org/configuration/nextjs
|
||||||
|
*/
|
||||||
|
export const getServerAuthSession = () => getServerSession(authOptions);
|
@ -7,7 +7,6 @@ declare global {
|
|||||||
CODE?: string;
|
CODE?: string;
|
||||||
BASE_URL?: string;
|
BASE_URL?: string;
|
||||||
PROXY_URL?: string;
|
PROXY_URL?: string;
|
||||||
VERCEL?: string;
|
|
||||||
HIDE_USER_API_KEY?: string; // disable user's api key input
|
HIDE_USER_API_KEY?: string; // disable user's api key input
|
||||||
DISABLE_GPT4?: string; // allow user to use gpt-4 or not
|
DISABLE_GPT4?: string; // allow user to use gpt-4 or not
|
||||||
BUILD_MODE?: "standalone" | "export";
|
BUILD_MODE?: "standalone" | "export";
|
||||||
|
Loading…
Reference in New Issue
Block a user