我最近使用指南here初始化了Keystone应用。我在代码中碰到的另一件事是在前端添加一个Next.js应用程序,并更改了mongodb连接字符串以指向我的MongoDB Atlas集群。我在Heroku上部署了此应用程序,它可以连接到数据库,并且一切正常,但是在尝试登录时,单击“登录”后,按钮会显示加载指示器一秒钟,然后再次显示登录页面。>
我已阅读文档并尝试放入
config: {
identityField: 'email',secretField: 'password'
}
在我的authStrategy
定义中为,但无济于事。真的不确定从这里还能去哪里。
这是我的Keystone
定义:
const keystone = new Keystone({
name: PROJECT_NAME,adapter: new Adapter({
mongoUri: 'mongodb+srv://stratus:WjbsEnmyBV80AJ6H@cluster0-qe4bs.azure.mongodb.net/stratus?retryWrites=true&w=majority',useNewUrlParser: true
}),});
// access control functions
const userIsAdmin = ({ authentication: { item: user } }) => Boolean(user && user.isAdmin);
const userOwnsItem = ({ authentication: { item: user } }) => {
if (!user) {
return false;
}
return { id: user.id };
};
const userIsAdminOrOwner = auth => {
const isAdmin = access.userIsAdmin(auth);
const isOwner = access.userOwnsItem(auth);
return isAdmin ? isAdmin : isOwner;
};
const access = { userIsAdmin,userOwnsItem,userIsAdminOrOwner };
keystone.createList('User',{
fields: {
name: { type: Text },email: {
type: Text,isUnique: true,},isAdmin: { type: Checkbox },password: {
type: Password,// To create an initial user you can temporarily remove access controls
access: {
read: access.userIsAdminOrOwner,update: access.userIsAdminOrOwner,create: access.userIsAdmin,delete: access.userIsAdmin,auth: true,});
const authStrategy = keystone.createAuthStrategy({
type: PasswordauthStrategy,list: 'User',config: {
identityField: 'email',secretField: 'password'
}
});
module.exports = {
keystone,apps: [
new GraphQLApp(),// To create an initial user you can temporarily remove the authStrategy below
new AdminUIApp({ enableDefaultRoute: true,authStrategy }),new NextApp({ dir: 'client'})
],};
我的Heroku日志中没有看到任何错误。任何帮助深表感谢!