javascript - Passport JS 不会将新模式保存到数据库?
问题描述
我正在尝试将 passport.js 与 GoogleStrategy 一起使用来授权用户使用我正在构建的 Web 应用程序。然后我想使用 mongoose 将用户存储在 MongoDB 中。
// Use the GoogleStrategy within Passport.
// Strategies in passport require a `verify` function, which accept
// credentials (in this case, a token, tokenSecret, and Google profile), and
// invoke a callback with a user object.
passport.use(
new GoogleStrategy({
clientID: keys.google.clientID,
clientSecret: keys.google.clientSecret,
callbackURL: '/google/redirect'
}, (accessToken, refreshToken, profile, done) => {
console.log(profile);
console.log(profile.displayName);
console.log(profile.id);
new Models.User({
username: profile.displayName,
googleID: profile.id,
memberOf: null
//console.log('got this far');
}).save(console.log('got to the save')).then((newUser) => {
console.log(newUser+'was created');
});
console.log('came down here');
})
)
那是我对护照和猫鼬的实施。从 Google 获取配置文件后,我会尝试将该用户的 displayName 和 googleID 存储在我想要保存到我的数据库中的用户架构中。我不确定我做错了什么,但是当我运行这个程序时,我看到所有console.log的输出到终端**except**
,我希望有人可以帮助我解决这个问题。console.log(newUser+'was created');
.then()
解决方案
更新:尝试在您的方法中添加一个错误处理程序,mongoose.connect()
以便您可以查看您的应用程序是否成功连接到您的数据库。这就是我的问题。
推荐阅读
- junit5 - 运行多个没有依赖关系的 JUnit5 测试用例
- java - 如何在 java swing 中获得焦点 jxBrowser
- amazon-web-services - 通过来自 JS/React FE Web 应用程序的 HTTP POST 请求的 AWS S3 存储桶
- regex - 用另一个字符替换正则表达式匹配中的所有字符?
- ruby - Ruby 类和访问
- ruby-on-rails - 如何从特定错误中挽救(Ruby on Rails)
- unity3d - 将游戏对象材质改回原始材质
- google-app-maker - (appmaker) 正确设置多选
- typescript - 如何使通用 TypeScript 接口从另一个通用接口扩展?
- reactjs - React Hooks,useReducer 无法获取状态