My ember app is using Firebase and Torii for authentication. I have created a service to capture the user's id so that application route will have access to it and be able to display user data. At first it changes the template and displays user data like it is supposed to, then when I refresh the page, the session stays authenticated, but the user data goes away. Any idea why this is happening/ how to fix it?
Here is my model hook in my Application Route:
auth: Ember.inject.service(),
beforeModel: function() {
return this.get("session").fetch().catch(function() {});
},
model: function() {
var currentID = this.get('auth').getCurrentUser();
if (currentID == 1) {
return this.get("session").fetch().catch(function() {});
}
else {
console.log("App id: "+currentID);
return this.store.find('user', currentID);
}
},
Here is my service:
import Ember from 'ember';
var defaultValue = 1;
export default Ember.Service.extend({
setCurrentUser: function(uid) {
defaultValue = uid;
return defaultValue;
},
getCurrentUser: function() {
return defaultValue;
}
});
Here is my login-form.js component:
import Ember from 'ember';
var inject = Ember.inject;
export default Ember.Component.extend({
firebaseApp: inject.service(),
auth: inject.service(),
actions: {
logIn: function(email, password) {
const auth = this.get('firebaseApp').auth();
var self = this;
auth.signInWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorCode);
console.log(errorMessage);
}).then(()=>{
let uid = auth.currentUser.uid;
console.log("uid: "+uid);
this.get('auth').setCurrentUser(uid);
this.sendAction('authorized');
});
}
}
});
Here is the authorized action in my Application Route:
authorized: function() {
console.log('authorized');
this.refresh();
}
And here is my login-form.hbs component:
<div id="header">
<nav>
<div class="page-container">
<ul><div class="lefter">
<li class="home-nav-name">Process</li>
</div>
<div class="righter">
<button class="login-button" >Log In</button>
</div>
</ul>
</div>
</nav>
</div>
Aucun commentaire:
Enregistrer un commentaire