MongoDB的下一个authjs发行
以下是我的[... NextAuth] .js文件,由于某种原因,当我尝试使用它来登录时,请访问http:// localhost:3000/api/auth/aign/sign,它显示了用户名和密码框,但是当我提交了我的错误。
http://localhost:3000/api/auth/error?error=Illegal%20arguments%3A%20undefined%2C%20undefined
但这不是告诉我什么是非法论点,有什么方法可以找出答案吗?
import NextAuth from "next-auth"
import CredentialsProvider from "next-auth/providers/credentials"
import clientPromise from "../../../lib/mongodb";
import jwt from "next-auth/jwt";
import { compare } from 'bcryptjs';
export default NextAuth({
session: {
jwt: true,
},
providers: [
CredentialsProvider({
// The name to display on the sign in form (e.g. 'Sign in with...')
name: 'DRN1',
credentials: {
username: { label: "Username", type: "text"},
password: { label: "Password", type: "password" }
},
async authorize(credentials, req) {
const client = await clientPromise
const { fieldvalue } = req.query
console.log("RUNNING THIS QUERY "+req.query)
const database = client.db('DRN1');
const users = await database.collection('users');
const result = await users.findOne({
username: credentials.username,
});
if (!result) {
client.close();
throw new Error('No user found with the username');
}
//Check hased password with DB password
const checkPassword = await compare(credentials.passowrd, result.passowrd);
//Incorrect password - send response
if (!checkPassword) {
client.close();
throw new Error('Password doesnt match');
}
//Else send success response
client.close();
return { username: result.username };
}
})
],
theme: {
colorScheme: "dark", // "auto" | "dark" | "light"
brandColor: "", // Hex color code
logo: "https://storage.googleapis.com/radiomedia-images/station_logos/v2/DRN1_small.png" // Absolute URL to image
}
});
Below is my [...nextauth].js file and for some reason when I try and use it to login by going to http://localhost:3000/api/auth/signin it presents the username and password box but then when I submit it I get an error.
http://localhost:3000/api/auth/error?error=Illegal%20arguments%3A%20undefined%2C%20undefined
But it is not telling me what the illegal argument is, is there any way to find out?
import NextAuth from "next-auth"
import CredentialsProvider from "next-auth/providers/credentials"
import clientPromise from "../../../lib/mongodb";
import jwt from "next-auth/jwt";
import { compare } from 'bcryptjs';
export default NextAuth({
session: {
jwt: true,
},
providers: [
CredentialsProvider({
// The name to display on the sign in form (e.g. 'Sign in with...')
name: 'DRN1',
credentials: {
username: { label: "Username", type: "text"},
password: { label: "Password", type: "password" }
},
async authorize(credentials, req) {
const client = await clientPromise
const { fieldvalue } = req.query
console.log("RUNNING THIS QUERY "+req.query)
const database = client.db('DRN1');
const users = await database.collection('users');
const result = await users.findOne({
username: credentials.username,
});
if (!result) {
client.close();
throw new Error('No user found with the username');
}
//Check hased password with DB password
const checkPassword = await compare(credentials.passowrd, result.passowrd);
//Incorrect password - send response
if (!checkPassword) {
client.close();
throw new Error('Password doesnt match');
}
//Else send success response
client.close();
return { username: result.username };
}
})
],
theme: {
colorScheme: "dark", // "auto" | "dark" | "light"
brandColor: "", // Hex color code
logo: "https://storage.googleapis.com/radiomedia-images/station_logos/v2/DRN1_small.png" // Absolute URL to image
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就我而言,错误在于比较密码。您需要检查该字符串。
我的凭证.密码不等于结果.密码,因为我写的
是而不是
希望,它会有所帮助。祝你好运。
In my case, the error was in comparing passwords. You need to check this string.
My credentials.password wasn't equal to result.password, becase I wrote
instead of
Hope, it will help. Good luck.