【问题标题】:ember-cli-mirage trying to stub auth0 (external) URLember-cli-mirage 尝试存根 auth0(外部)URL
【发布时间】:2019-10-13 06:00:03
【问题描述】:

我正在开发一个新的 Ember.js 项目并使用 ember-cli-mirage 来排除我的请求。该项目将使用ember-simple-auth 和 Auth0 进行用户身份验证。我开始在我的项目中实现它们,但是当我尝试使用 Auth0 登录模式使用我的 Google 帐户注册时,控制台中出现了一个奇怪的错误:

Your Ember app tried to GET 'https://(my auth0 domain).auth0.com/userinfo',
but there was no route defined to handle this request.
Define a route that matches this path in your
mirage/config.js file. Did you forget to add your namespace?

(我的 auth0 域在上面编辑)

我不知道为什么 Mirage 会尝试存根对外部 URL 的请求。我正在阅读 Mirage 文档并尝试在我的 mirage/config.js 文件中使用 this.passthrough(),这样 Mirage 会发出真正的请求,但这似乎没有效果(我猜它只明确适用于 namespace 内的路由在配置文件中定义)。

谁能帮助我了解为什么会发生这种情况以及如何阻止 Mirage 这样做?谢谢!

【问题讨论】:

  • @Selman 抱歉,不确定评论回复是否如此苛刻(这是预设选项之一) - 为什么建议删除 ember-cli-mirage 标签?

标签: ember.js auth0 ember-simple-auth ember-cli-mirage


【解决方案1】:

Ember CLI Mirage 默认拦截所有 ajax (XMLHttpRequest) 和fetch 请求。您必须使用 server.passthrough() 方法将应通过的请求列入白名单。 (thismirage/config.js 中的 server 实例。)您可以将相对和绝对 URL 与 server.passthrough 以及所有路由处理程序一起使用。所以server.passthrough('https://(my auth0 domain).auth0.com/userinfo') 应该可以解决您的问题。

【讨论】:

  • 做到了!非常感谢@jelhan!我没有意识到 Mirage 会模拟所有请求,很高兴知道。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多