-
I know this seems like a trivial question but I just can't seem to figure it out! my authOptions if it helps import { connectDB } from "@/lib/mongodb";
import User from "@/models/User";
import type { NextAuthOptions } from "next-auth";
import credentials from "next-auth/providers/credentials";
import bcrypt from "bcryptjs";
export const authOptions: NextAuthOptions = {
providers: [
credentials({
name: "Credentials",
id: "credentials",
credentials: {
email: { label: "Email", type: "text" },
password: { label: "Password", type: "password" },
},
async authorize(credentials) {
await connectDB();
const user = await User.findOne({
email: credentials?.email,
}).select("+password");
if (!user) throw new Error("CredentialsSignin");
const passwordMatch = await bcrypt.compare(
credentials!.password,
user.password,
);
if (!passwordMatch) throw new Error("CredentialsSignin");
return user;
},
}),
],
session: {
strategy: "jwt",
},
pages: {
signIn: "/login",
},
}; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Figured it out! |
Beta Was this translation helpful? Give feedback.
Figured it out!
In the route, instead of using getServerSession() use getToken() e.g.
and pass the token as a header when doing the fetch