处理通过Vue-Router的电子邮件确认重定向

发布于 2025-01-22 08:29:40 字数 2631 浏览 0 评论 0原文

我正在研究使用vue.jsauth0构建前端的项目,并将其作为IDP使用。

当用户登录并首次登录时,他们会被路由到/verify-email,其中包含一张注释,要求他们检查其电子邮件以验证其帐户。

单击电子邮件确认链接后,我期望以下请求:

http://localhost:3000/?supportSignUp=true
  &supportForgotPassword=true
  &email=john.doe%40exampleco.com
  &message=Your%20email%20was%20verified.%20You%20can%20continue%20using%20the%20application.
  &success=true#/register

因为它与Spas有关URLS“ rel =” nofollow noreferrer“> auth0的文档建议处理请求如下:

var express = require('express');
var router = express.Router();
var qs = require('qs'); // to read query string params and stringify them

router.get('/register', function(req, res, next) {
  var route = req.query.route; // retrieve the route param that contains the SPA client side route user needs to be redirected to.

  delete req.query.route; // remove it from query params.
  res.redirect('http://localhost:3000/#/' + route + '?' +  qs.stringify(req.query)); // Send a 302 redirect for the expected route
});

module.exports = router;

我的项目使用vue-router而不是Express来处理路线,因此我遵循相关文档 并进行了以下内容:

{
  path: '/account-confirmed/:emailVerificationParams',
  redirect: to => {
    return { path: '/', query: { q: to.params.emailVerificationParams } }
  },
},

当用户确认帐户时,他们被发送到> /帐户确认,它依次应将其重定向到/,这是一个受保护的路径,应提示他们在访问应用程序之前输入其登录凭据。

当我通过运行以下操作在URL中手动测试它时,重定向可以正常工作:

http://localhost:3000/?supportSignUp=true
  &supportForgotPassword=true
  &email=john.doe%40exampleco.com
  &message=Your%20email%20was%20verified.%20You%20can%20continue%20using%20the%20application.
  &success=true#/register

或:

http://cf_distribution_url/?supportSignUp=true
  &supportForgotPassword=true
  &email=john.doe%40exampleco.com
  &message=Your%20email%20was%20verified.%20You%20can%20continue%20using%20the%20application.
  &success=true#/register

通过运行,我的意思是,我正在通过在浏览器的URL地址栏中手动输入它们,就像我想访问一样GoogleFacebook的网站或stack Overflow

但是,当我单击电子邮件确认链接时,重定向不起作用。我会收到403错误作为响应,而我希望提示再次登录。

考虑到这一点,我有2个问题:

  1. 我当前的重定向实施是什么问题?
  2. 我该如何修复?

I'm working on project where the front-end is built with Vue.js and Auth0 is being leveraged as the IDP.

When a user signs up and logs in for the first time, they get routed to /verify-email which contains a note asking them to check their email to verify their account.

Upon clicking on the email confirmation link, I am expecting the following request:

http://localhost:3000/?supportSignUp=true
  &supportForgotPassword=true
  &email=john.doe%40exampleco.com
  &message=Your%20email%20was%20verified.%20You%20can%20continue%20using%20the%20application.
  &success=true#/register

As it pertains to SPAs, Auth0's documentation recommends handling the request as follow:

var express = require('express');
var router = express.Router();
var qs = require('qs'); // to read query string params and stringify them

router.get('/register', function(req, res, next) {
  var route = req.query.route; // retrieve the route param that contains the SPA client side route user needs to be redirected to.

  delete req.query.route; // remove it from query params.
  res.redirect('http://localhost:3000/#/' + route + '?' +  qs.stringify(req.query)); // Send a 302 redirect for the expected route
});

module.exports = router;

My project uses Vue-Router instead of Express to handle routes, so I followed the relevant documentation and did the following:

{
  path: '/account-confirmed/:emailVerificationParams',
  redirect: to => {
    return { path: '/', query: { q: to.params.emailVerificationParams } }
  },
},

When a user confirms their account, they get sent to /account-confirmed which in turns should redirect them to /, which is a protected path, and should prompt them to enter their login credentials before accessing the application.

The redirect works fine when I test it manually in url by running the following:

http://localhost:3000/?supportSignUp=true
  &supportForgotPassword=true
  &email=john.doe%40exampleco.com
  &message=Your%20email%20was%20verified.%20You%20can%20continue%20using%20the%20application.
  &success=true#/register

or:

http://cf_distribution_url/?supportSignUp=true
  &supportForgotPassword=true
  &email=john.doe%40exampleco.com
  &message=Your%20email%20was%20verified.%20You%20can%20continue%20using%20the%20application.
  &success=true#/register

By running, I mean I am navigating to the urls by inputting them manually in the url address bar of my browser just as I would if I wanted to visit the sites of Google, Facebook, or Stack Overflow.

However, when I click on the email confirmation link, the redirect does not work. I get a 403 error as a response, whereas I'm expecting to be prompted to login again.

With that in mind, I have 2 questions:

  1. What's wrong with my current redirect implementation?
  2. How do I fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘然心甜 2025-01-29 08:29:40

曲折的是,与vue相比,与auth0相比,问题更多。要解决我的问题,我只需要 oidc 中的力量重新验证

As it turns, the issue was more with Auth0 than it was with Vue. To resolve my issue, I just had to Force Reauthentication in OIDC

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文