Noob here. I see data in the console, but it’s not rendered in my template.
I’m currently working on a two-step registration system. Where you first sign up using email or facebook, then, complete your profile on the next page.
I’m trying render the information captured from the first step (email) and place it into the input field on the second step.
How i imagine it should work:
- Signup with email & password, send data to backend, and trigger authentication.
- An auth session cookie is created & stored. This contains user ID & email.
- Transition to the next route, the edit profile form.
- In the application route, query user data based on user ID. Set the data as model.
- Pass the model into the form template, and see the form fields get pre-populated.
But i’m stuck in the last step.
Here’s my code:
// routes/application.js
// get the current logged in user, put the data inside model
// reference: https://github.com/simplabs/ember-simple-auth/blob/master/guides/managing-current-user.md#loading-the-current-user
model() {
return RSVP.hash({
// problem: this returns empty
currentUser: this._getCurrentUser()
});
},
sessionAuthenticated() {
this._super(...arguments);
this._getCurrentUser();
},
_getCurrentUser() {
let authenticated = this.get('session.isAuthenticated');
if (authenticated) {
// session does exists and this section does get executed
let id = this.get('session.data.authenticated.id');
let access_token = this.get('session.data.authenticated.access_token');
// fetch user data via AJAX
return this.get('user').getUser(id, access_token).then((response) => {
return response;
}, (response) => {
throw response;
});
} else {
return {};
}
}
The ajax service itself:
// services/user.js
getUser(id, access_token) {
console.log('>> services.auth.getUser');
return this.get('ajax').request('/members', {
data: { id, access_token }
});
},
And in the profile form page:
// templates/register-profile.hbs
// problem: the model.currentUser returns empty
{{log ">> currentUser" model.currentUser}}
<div class="row">
<div class="columns small-12 medium-8">
...
{{form-profile currentUser=model.currentUser}}
</div>
</div>
Although if i refresh the page, the email field inside {{form-profile}}
gets populated correctly with the email address.
Any feedback would be really appreciated. Thx a lot!