Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Emberjs身份验证会话不工作_Javascript_Rest_Session_Authentication_Ember.js - Fatal编程技术网

Javascript Emberjs身份验证会话不工作

Javascript Emberjs身份验证会话不工作,javascript,rest,session,authentication,ember.js,Javascript,Rest,Session,Authentication,Ember.js,我也跟着,但遇到了一些问题 我有一个php后端api,它位于另一个域{localdevelopment} ember js应用程序使用ember应用程序工具包并连接到rest api。 当用户提交登录表单时,它会将用户名/带有密码的电子邮件发送到RESTAPI中定义的路由之一 在结果变量中接收api结果后,如下所示: Object {success: "user login success", session: "2OmwKLPclC.YhYAT3745467my7t0m2uo", user_i

我也跟着,但遇到了一些问题

我有一个php后端api,它位于另一个域{localdevelopment} ember js应用程序使用ember应用程序工具包并连接到rest api。 当用户提交登录表单时,它会将用户名/带有密码的电子邮件发送到RESTAPI中定义的路由之一

在结果变量中接收api结果后,如下所示:

Object {success: "user login success", session: "2OmwKLPclC.YhYAT3745467my7t0m2uo", user_id: "1"}
但一旦我捕获数据并将其发送到位于

控制台上有个错误,说

Uncaught TypeError: Object function () {
    if (!wasApplied) {
      Class.proto(); // prepare prototype...
    }
    o_defineProperty(this, GUID_KEY, undefinedDescriptor);
    o_defineProperty(this, '_super', undefinedDescriptor);
    var m = met...<omitted>...e' new.js:23
(anonymous function) new.js:23
jQuery.Callbacks.fire jquery.js:1037
jQuery.Callbacks.self.fireWith jquery.js:1148
done jquery.js:8074
jQuery.ajaxTransport.send.callback jquery.js:8598

它无法将变量传递给导入的函数

终于成功了。我所做的错误是在auth_manager.js上扩展了Ember.Object.extend之后,我没有在任何地方创建对象。这就是为什么它不能设置创建cookie并抛出错误消息的原因

我所要做的就是在扩展对象后创建.create

不知道这是不是正确的方法。但它确实有效

import User from 'lms/models/user';
import Application from 'lms/adapters/application';
var AuthManager = Ember.Object.extend({

    init: function() {
        this._super();
        var accessToken = $.cookie('access_token');
        var authUserId = $.cookie('auth_user');
        if(!Ember.isEmpty(accessToken) || !Ember.isEmpty(authUserId)) {
            this.authenticate(accessToken, authUserId);
        }
    },

    isAuthenticated: function() {
        return !Ember.isEmpty(this.get('ApiKey.accessToken')) && !Ember.isEmpty(this.get('ApiKey.user'));
    },

    authenticate: function(accessToken, userId) {
        $.ajaxSetup({
            headers: { 'Authorization': 'Bearer ' + accessToken }
        });
        var user = User.store.find(userId);
        console.log(user);
        this.set('ApiKey', ApiKey.create({
            accessToken: accessToken,
            user: user
        }));
    },

    reset: function() {
        this.set('ApiKey', null);
        $.ajaxSetup({
            headers: { 'Authorization': 'Bearer None' }
        });
    },

    apiKeyObserver: function() {
        Application.accessToken = this.get('apikey.accessToken');
        if (Ember.isEmpty(this.get('ApiKey'))) {
            $.removeCookie('access_token');
            $.removeCookie('auth_user');
        } else {
            $.cookie('access_token', this.get('ApiKey.accessToken'));
            $.cookie('auth_user', this.get('ApiKey.user.id'));
        }
    }.observes('ApiKey')
});

export default AuthManager;
Uncaught TypeError: Object function () {
    if (!wasApplied) {
      Class.proto(); // prepare prototype...
    }
    o_defineProperty(this, GUID_KEY, undefinedDescriptor);
    o_defineProperty(this, '_super', undefinedDescriptor);
    var m = met...<omitted>...e' new.js:23
(anonymous function) new.js:23
jQuery.Callbacks.fire jquery.js:1037
jQuery.Callbacks.self.fireWith jquery.js:1148
done jquery.js:8074
jQuery.ajaxTransport.send.callback jquery.js:8598