简体   繁体   English

嵌入简单身份验证将用户配置文件保存在会话中

[英]ember simple auth save user profile in a session

I can't find out why the method set of session this.get('session').set('name', name); 我无法找出原因的方法set会议的this.get('session').set('name', name); does not persist after having reloaded the page. 重新加载页面后无法保存。 I followed exactly what was mentioned here . 我完全按照这里所说的去做

My code 我的密码

//controllers/authentification.js
import Ember from 'ember';

export default Ember.Controller.extend({

session: Ember.inject.service('session'),
actions: {
    authenticate() {
        var this2 = this;
        let {
            email, motDePasse
        } = this.getProperties('email', 'motDePasse');

        this.get('session').authenticate('authenticator:oauth2', email, motDePasse).then(function () {
            this2.store.queryRecord('membre', {
                membre: {
                    email: email
                }
            }).then(function (membre) {
                var nom = membre.get('nom');
                this2.get('session').set('nom', nom);
                console.log('name:', nom);
            });
        }).catch((reason) => {
            this.set('errorMessage', reason.error || reason);
        });
    }
}
});

for the session-store/sessions.js 用于session-store / sessions.js

import Cookie from 'ember-simple-auth/session-stores/cookie';

export default Cookie.extend();

controllers/application.js 控制器/application.js

import Ember from 'ember';
import SessionService from 'ember-simple-auth/services/session';

export default Ember.Controller.extend({
    session: Ember.inject.service('session'),
    index: function () {
        this.transitionTo('index');
    }
});

template/application.js 模板/application.js

<ul class="nav navbar-nav navbar-right">
{{#if session.isAuthenticated}}
   <li>nom :{{session.nom}}</li>
   <li><a {{action 'logout' on="click"}}>Deconnecter</a></li>
{{else}}
   {{#link-to 'authentification' tagName="li"}}<a href>Authentification</a>{{/link-to}}
{{/if}}
</ul>

the first time i authenticate, the variable "nom" appears but once i reload the page, the variable "nom" disappears but the session stille isAuthenticated 我第一次进行身份验证时,会出现变量“ nom”,但是一旦我重新加载页面,变量“ nom”就消失了,但会话stille已通过身份验证

i have found the solution , i have just to use 我已经找到了解决方案,我只需要使用

this2.get('session').set('.data.nom', nom);

instead of 代替

this2.get('session').set('nom', nom);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM