【问题标题】:How to implement steam auth into nuxt如何在 nuxt 中实现 Steam 身份验证
【发布时间】:2018-09-17 17:21:13
【问题描述】:

nuxt 上有一个现成的站点。我正在寻找一种实现授权的方法。我找到了使用 express.js steam-login 进行授权的包,一切正常.. 现在路由 /login / logout 等如何开始工作以及如何在渲染时使用收到的关于 nuxt 中用户的数据?我尝试使用中间件,但没有任何反应。谢谢。

有获取数据的例子

app.use(steam.middleware({
realm: 'http://localhost:3000/', 
verify: 'http://localhost:3000/verify',
apiKey: "api key"}));

app.get('/authenticate', steam.authenticate(), function(req, res) {
res.redirect('/');});

我们可以使用 nuxt builder,我没有找到将这些数据传输到 nuxt 并在模板中使用的方法。和 routs nuxt 重叠 routs express

const nuxt = new Nuxt()
nuxt.build()
  .then(() => {  
    app.use(nuxt.render)
    app.listen(3000)})

【问题讨论】:

标签: node.js express steam nuxt.js


【解决方案1】:

用 serverMiddleware 解决了这个问题。

在 nuxt.config 中添加了新的 custum 中间件

serverMiddleware: [
   '~/api/index'
]

app.use(require('express-session')({ resave: false, saveUninitialized: false, secret: 'a secret' }));

app.use(steam.middleware({
   realm: 'http://localhost:3000/', 
   verify: 'http://localhost:3000/login/verify',
   apiKey: "apiKey"}
));

app.get('/', function(req, res) {
    res.send(req.user == null ? 'no user' : req.user).end();
});

app.get('/authenticate', steam.authenticate(), function(req, res) {
    res.redirect('/login/');
});

app.get('/logout', steam.enforceLogin('/'), function(req, res) {
    req.logout();
    res.redirect('/');
});


module.exports = {
    path: '/login/',
    handler: app
};

在我的模板中使用 axois 从 /login 路由获取此数据。谢谢

【讨论】:

  • 你还有这个解决方案吗?
猜你喜欢
  • 2017-11-29
  • 2013-09-11
  • 2017-06-16
  • 2018-09-29
  • 2017-10-26
  • 2020-07-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多