【问题标题】:Error: No default account store is mapped to the specified application错误:没有默认帐户存储映射到指定的应用程序
【发布时间】:2016-09-08 19:12:43
【问题描述】:

我在这里关注了文档:https://github.com/stormpath/express-stormpath

错误:没有默认帐户存储映射到指定的应用程序

当我尝试运行我的应用程序时,我在控制台中收到上述错误。这很可能是我的代码有问题,还是我应该转到 Stormpath 网站上的管理页面?

我使用 windows 命令 setx 来设置环境变量,如果我的 app.js 文件中有 api 密钥和秘密,我不确定是否需要这样做。对于这个问题,我用 XXXXXXXX 删除了敏感信息。

var express = require('express');
var app = express();

//Stormpath
var stormpath = require('express-stormpath');

//Init Stormpath
app.use(stormpath.init(app, {

    apiKey: {id:'XXXXXXXXXX', secret: 'XXXXXXXXXX'},
    secretKey: 'random_string_of_words_go_here',
    application: 'https://api.stormpath.com/v1/accounts/XXXXXXXXX'

}));

//home:
app.get('/', function(req, res){
    res.render('home');
    console.log(req.session);
});

app.get('/create-quiz', stormpath.loginRequired, function(req, res){
    res.render('createQuiz');
});


//404 page:
app.use(function(req, res, next){
    res.status(404);
    res.render('404');
});

//500 page:
app.use(function(err, req, res, next){
    console.error(err.stack);
    res.status(500);
    res.render('500');
});

app.on('stormpath.ready', function () {
    console.log('Stormpath ready...')
});

app.listen(app.get('port'), function(){
    console.log('Express started on http://localhost: ' + app.get('port') + '; Press ctrl-C to terminate.')
});

提前感谢您的帮助。

【问题讨论】:

    标签: node.js express stormpath express-stormpath


    【解决方案1】:

    是的!此错误很可能是因为您在管理控制台中配置了 Stormpath 应用程序。

    每个应用程序都需要一个“目录”来存储您的帐户,而您似乎没有一个。

    尝试登录 Stormpath 并在管理控制台中添加一个“目录”来存储您的帐户。如果这样做,请尝试确保选中“默认帐户位置”。

    这是我的样子。希望这会有所帮助!

    (来源:我在 Stormpath 工作)

    【讨论】:

    • 谢谢爱德华!原来我的目录没问题。在我使用“set”而不是“setx”作为我的 apikey id、secret 和应用程序 href 之后,它开始工作。感谢您花时间阅读我的问题并提供对目录的深入了解,这有助于我确认这是按顺序进行的。
    • 酷!只是好奇,您从哪里获得以下代码:app.use(stormpath.init(app, { apiKey: {id:'XXXXXXXXXX', secret: 'XXXXXXXXXX'}, secretKey: 'random_string_of_words_go_here', application: 'https://api.stormpath.com/v1/accounts/XXXXXXXXX' })); 我认为您配置 express-stormpath 的方式不正确。虽然它可能来自旧的博客文章/文档?
    • 看起来文档说要将应用程序包装在一个对象中(这可能是它找不到应用程序的“帐户存储”的原因)docs.stormpath.com/nodejs/express/latest/…
    • 嗨,Edward,我回头看,找不到确切的来源,但我确实按照您的指定将应用程序包装在一个对象中,它运行良好。感谢您指出这一点!
    • 没问题。还对 secretKey 参数感到困惑...无论如何,通常建议使用环境变量,因为它们不会出现在您的 git 历史记录中,而且很容易更改——但无论哪种方式都有效! =]
    猜你喜欢
    • 2010-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-24
    • 2019-11-10
    • 2019-05-23
    • 2017-06-07
    • 2018-05-19
    相关资源
    最近更新 更多