【问题标题】:ember-simple-auth and torii firebase TypeError: Converting circular structure to JSONember-simple-auth 和 torii firebase TypeError:将循环结构转换为 JSON
【发布时间】:2017-06-05 20:11:19
【问题描述】:

我开始让 torri 和 emberfire 为登录页面工作,但是当我尝试将其与 ember simple auth 一起使用时,我收到错误:

TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at Class.persist (local-storage.js:45)
    at Class.persist (adaptive.js:163)
    at Class._callStoreAsync (internal-session.js:132)
    at Class._updateStore (internal-session.js:207)
    at Class._setup (internal-session.js:156)
    at internal-session.js:61
    at tryCatch (ember.debug.js:50180)
    at invokeCallback (ember.debug.js:50195)
    at publish (ember.debug.js:50163)

不确定是错误还是我遗漏了需要设置的内容。做了一个快速的 repo,它显示了我的问题 https://github.com/tobias-g/ember-simple-auth-firebase,其中 diff https://github.com/tobias-g/ember-simple-auth-firebase/commit/02882f4db3a0320d4ac314d2e92192ac522470f8 显示了我添加的内容以尝试让 ember simple auth 工作。

DEBUG: -------------------------------
DEBUG: Ember             : 2.13.3
DEBUG: Ember Data        : 2.13.1
DEBUG: Firebase          : 3.9.0
DEBUG: EmberFire         : 0.0.0
DEBUG: jQuery            : 3.2.1
DEBUG: Ember Simple Auth : 1.3.0
DEBUG: -------------------------------

【问题讨论】:

  • 您知道,Firebase 拥有自己的身份验证系统,该系统已经使用 Torii。我不知道你的用例是什么,但我发现 ember-simple-auth 和 Firebase 是多余的。 github.com/firebase/emberfire/blob/master/docs/guide/…
  • 是的,我在第一次提交时得到了 firebase 身份验证工作正常,但我想将 ember-simple-auth DataAdapterMixin 用于我的模型,将 AuthenticatedRouteMixin 用于路由。如果我不能修复它,我猜我必须在没有 mixins 的情况下自己处理这个问题,并且可能需要编写更多样板代码。

标签: firebase ember.js ember-simple-auth emberfire


【解决方案1】:

Emberfire 发回的data.authenticated 载荷过于复杂,并且具有循环引用。 Ember Simple Auth 将此有效负载存储到本地存储中,以防止在其他选项卡上刷新或打开应用时出现登录提示。

似乎现在对我有用(我没有进行太多测试)是扩展会话存储。 YMMV。

// app/session-stores/application.js

import AdaptiveStore from 'ember-simple-auth/session-stores/adaptive';

export default AdaptiveStore.extend({

  persist(data) {
    const a = data.authenticated;

    const subset = {
      authenticator: a.authenticator,
      email: a.email,
      provider: a.provider,
      refreshToken: a.refreshToken,
      uid: a.uid
    }

    return this._super({ authenticated: subset });
  }

});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 2018-10-05
    • 2016-01-22
    • 2017-06-29
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多