i can't find out why the the function "set" on session "this.get('session').set('name', name);" does not persist after having reloaded the page i followed exactly what was mentioned in https://github.com/simplabs/ember-simple-auth/
我无法找出为什么功能“设置”在会话“this.get('session')。set('name',name);”在重新加载页面之后我没有坚持,我完全遵循https://github.com/simplabs/ember-simple-auth/中提到的内容
here is 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是Authenticheated
1 个解决方案
#1
1
i have found the solution , i have just to use
我找到了解决方案,我刚刚使用
this2.get('session').set('.data.nom', nom);
this2.get('session')。set('。data.nom',nom);
instead of
代替
this2.get('session').set('nom', nom);
#1
1
i have found the solution , i have just to use
我找到了解决方案,我刚刚使用
this2.get('session').set('.data.nom', nom);
this2.get('session')。set('。data.nom',nom);
instead of
代替
this2.get('session').set('nom', nom);