mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-08 08:39:36 -04:00
Fix router
This commit is contained in:
@@ -1,18 +1,86 @@
|
||||
import NextAuth from "next-auth";
|
||||
import { authOptions } from "@/auth";
|
||||
import NextAuth, {type NextAuthOptions} from "next-auth";
|
||||
import GoogleProvider from "next-auth/providers/google";
|
||||
import CredentialsProvider from "next-auth/providers/credentials";
|
||||
import {PrismaAdapter} from "@next-auth/prisma-adapter";
|
||||
import {prisma} from "@/lib/prisma";
|
||||
import bcrypt from "bcryptjs";
|
||||
|
||||
const handler = NextAuth(authOptions);
|
||||
export { handler as GET, handler as POST };
|
||||
export const authOptions = {
|
||||
providers: [
|
||||
GoogleProvider({
|
||||
clientId: process.env.GOOGLE_CLIENT_ID!,
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
||||
}),
|
||||
CredentialsProvider({
|
||||
name: "credentials",
|
||||
credentials: {
|
||||
email: {label: "Email", type: "email"},
|
||||
name: {label: "Name", type: "name"},
|
||||
password: {label: "Password", type: "password"},
|
||||
},
|
||||
async authorize(credentials) {
|
||||
if (!credentials?.email || !credentials?.password) {
|
||||
throw new Error("Email and password are required");
|
||||
}
|
||||
|
||||
declare module "next-auth" {
|
||||
interface Session {
|
||||
user: { id: string; name: string; email: string };
|
||||
// user: { id: string };
|
||||
}
|
||||
}
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {email: credentials.email},
|
||||
});
|
||||
|
||||
declare module "next-auth/jwt" {
|
||||
interface JWT {
|
||||
id: string;
|
||||
}
|
||||
}
|
||||
if (!user || !user.password) {
|
||||
throw new Error("Invalid email or password");
|
||||
}
|
||||
|
||||
const isCorrectPassword = await bcrypt.compare(
|
||||
credentials.password,
|
||||
user.password
|
||||
);
|
||||
|
||||
if (!isCorrectPassword) {
|
||||
throw new Error("Invalid email or password");
|
||||
}
|
||||
console.log(user);
|
||||
return user;
|
||||
},
|
||||
}),
|
||||
],
|
||||
pages: {
|
||||
signIn: "/login",
|
||||
},
|
||||
session: {
|
||||
strategy: "database",
|
||||
},
|
||||
adapter: PrismaAdapter(prisma),
|
||||
debug: process.env.NODE_ENV === "development",
|
||||
secret: process.env.NEXTAUTH_SECRET,
|
||||
// callbacks: {
|
||||
// async jwt({ token, user }) {
|
||||
// return { ...token, id: token.id ?? user?.id };
|
||||
// },
|
||||
// async session({ session, token }) {
|
||||
// return { ...session, user: { ...session.user, id: token.id } };
|
||||
// },
|
||||
// },
|
||||
} satisfies NextAuthOptions;
|
||||
|
||||
// Export **named** HTTP handlers (required by App Router)
|
||||
console.log("Auth route hit");
|
||||
|
||||
// export const { handlers, auth, signIn, signOut } = NextAuth(authOptions);
|
||||
const authHandler = NextAuth(authOptions);
|
||||
// export const GET = handlers.GET;
|
||||
// export const POST = handlers.POST;
|
||||
export { authHandler as GET, authHandler as POST };
|
||||
|
||||
// declare module "next-auth" {
|
||||
// interface Session {
|
||||
// user: { id: string; name: string; email: string };
|
||||
// // user: { id: string };
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// declare module "next-auth/jwt" {
|
||||
// interface JWT {
|
||||
// id: string;
|
||||
// }
|
||||
// }
|
||||
|
||||
61
auth.ts
61
auth.ts
@@ -1,61 +0,0 @@
|
||||
import CredentialsProvider from "next-auth/providers/credentials";
|
||||
import GoogleProvider from "next-auth/providers/google";
|
||||
import {type NextAuthOptions} from "next-auth";
|
||||
import bcrypt from "bcryptjs";
|
||||
import { PrismaAdapter } from "@next-auth/prisma-adapter";
|
||||
import {prisma} from "@/lib/prisma"
|
||||
|
||||
export const authOptions = {
|
||||
providers: [
|
||||
GoogleProvider({
|
||||
clientId: process.env.GOOGLE_CLIENT_ID!,
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
||||
}),
|
||||
CredentialsProvider({
|
||||
name: "credentials",
|
||||
credentials: {
|
||||
email: {label: "Email", type: "email"},
|
||||
name: {label: "Name", type: "name"},
|
||||
password: {label: "Password", type: "password"},
|
||||
},
|
||||
async authorize(credentials) {
|
||||
if (!credentials?.email || !credentials?.password) {
|
||||
throw new Error("Email and password are required");
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {email: credentials.email},
|
||||
});
|
||||
|
||||
if (!user || !user.password) {
|
||||
throw new Error("Invalid email or password");
|
||||
}
|
||||
|
||||
const isCorrectPassword = await bcrypt.compare(
|
||||
credentials.password,
|
||||
user.password
|
||||
);
|
||||
|
||||
if (!isCorrectPassword) {
|
||||
throw new Error("Invalid email or password");
|
||||
}
|
||||
|
||||
return user;
|
||||
},
|
||||
}),
|
||||
],
|
||||
pages: {
|
||||
signIn: "/login",
|
||||
},
|
||||
adapter: PrismaAdapter(prisma),
|
||||
debug: process.env.NODE_ENV === "development",
|
||||
secret: process.env.NEXTAUTH_SECRET,
|
||||
// callbacks: {
|
||||
// async jwt({ token, user }) {
|
||||
// return { ...token, id: token.id ?? user?.id };
|
||||
// },
|
||||
// async session({ session, token }) {
|
||||
// return { ...session, user: { ...session.user, id: token.id } };
|
||||
// },
|
||||
// },
|
||||
} satisfies NextAuthOptions;
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -16,7 +16,7 @@
|
||||
"bcryptjs": "^3.0.2",
|
||||
"lucide-react": "^0.503.0",
|
||||
"next": "^15.4.4",
|
||||
"next-auth": "^4.24.7",
|
||||
"next-auth": "^4.24.11",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"react-icons": "^5.5.0"
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
"bcryptjs": "^3.0.2",
|
||||
"lucide-react": "^0.503.0",
|
||||
"next": "^15.4.4",
|
||||
"next-auth": "^4.24.7",
|
||||
"next-auth": "^4.24.11",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"react-icons": "^5.5.0"
|
||||
|
||||
Reference in New Issue
Block a user