gpt4 book ai didi

node.js - SANE 堆栈和 Passportjs

转载 作者:搜寻专家 更新时间:2023-11-01 00:42:37 24 4
gpt4 key购买 nike

我正在使用 sane stack我想添加 passportjs

我使用说明在 sails 应用程序中成功实现了 passportjs here .我正在尝试使用这些指令将 passportjs 添加到一个正常的应用程序中。我也在考虑尝试让 sails 为登录、注销等页面提供服务,因为这些指令使用 sails 的 View 。这可能不是最好的决定,但现在我只想要一些有用的东西。

我在登录时遇到以下错误。

error: Sending 500 ("Server Error") response:
server | TypeError: undefined is not a function
server | at Object.AuthController.login (/Users/someUser/Documents/sanestack/project/server/api/controllers/AuthController.js:50:9)
server | at bound (/usr/local/lib/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21)
server | at routeTargetFnWrapper (/usr/local/lib/node_modules/sails/lib/router/bind.js:179:5)
server | at callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:164:37)
server | at param (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:138:11)
server | at pass (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:145:5)
server | at nextRoute (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:100:7)
server | at callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:167:11)
server | at /usr/local/lib/node_modules/sails/lib/router/bind.js:187:7
server | at /Users/someUser/Documents/sanestack/project/server/api/policies/passport.js:32:7
server | at SessionStrategy.strategy.pass (/Users/someUser/Documents/sanestack/project/server/node_modules/passport/lib/middleware/authenticate.js:318:9)
server | at SessionStrategy.authenticate (/Users/someUser/Documents/sanestack/project/server/node_modules/passport/lib/strategies/session.js:67:10)
server | at attempt (/Users/someUser/Documents/sanestack/project/server/node_modules/passport/lib/middleware/authenticate.js:341:16)
server | at authenticate (/Users/someUser/Documents/sanestack/project/server/node_modules/passport/lib/middleware/authenticate.js:342:7)
server | at /Users/someUser/Documents/sanestack/project/server/api/policies/passport.js:28:23
server | at initialize (/Users/someUser/Documents/sanestack/project/server/node_modules/passport/lib/middleware/initialize.js:62:5) [TypeError: undefined is not a function]

问题出在 server/api/controllers/AuthController.js 中的以下代码

 33   login: function (req, res) {
34 var strategies = sails.config.passport
35 , providers = {};
36
37 // Get a list of available providers for use in your templates.
38 Object.keys(strategies).forEach(function (key) {
39 if (key === 'local') {
40 return;
41 }
42
43 providers[key] = {
44 name: strategies[key].name
45 , slug: key
46 };
47 });
48
49 // Render the `auth/login.ext` view
50 res.view({
51 providers : providers
52 , errors : req.flash('error')
53 });
54 },

还有/server/api/policies/passport.js 中的以下代码

 24 module.exports = function (req, res, next) {
25 // Initialize Passport
26 passport.initialize()(req, res, function () {
27 // Use the built-in sessions
28 passport.session()(req, res, function () {
29 // Make the user available throughout the frontend
30 res.locals.user = req.user;
31
32 next();
33 });
34 });
35 };

如有任何帮助,我们将不胜感激。

最佳答案

我相信您遇到了这个问题,因为您正在尝试使用 Sails 服务器 View ,而 Sane 堆栈期望 Ember 处理所有 View ...如果您查看 https://github.com/mgenev/how-to-sane你会在那里看到客户端/服务器身份验证交互以及两者如何一起玩,它不是基于 Passport 的,它有一些待处理的工作,但你可以得到一般情况

关于node.js - SANE 堆栈和 Passportjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29597491/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com