My goal is to get the currently logged in user’s email and save it to the message model when adding a new message to a chat box. What is the best way to get this information into the controller to later be saved in a model? I can currently use session in my .hbs like so {{session.currentUser.email}}
Do you have a user
property on your message
model? message
would belongsTo
a user
when you createRecord
for a new message, the user
would be passed along.
If you’re asking how to get at the currentUser
in the session
(I’m assuming this is a service) in your controller (assuming you have the service injected in the controller somehow already) you can
// If currentUser is a property of the session service
this.get('session.currentUser')
I do indeed have a belongsTo
user on the message model but I’m not really sure how to associate a message with the logged in user. I guess that’s why I was trying to use the user session.
I am using torii
to start and create sessions like so,
this.get('session').open('firebase', {
provider: 'password',
email: email,
password: password
})
Basically I have access to anything session related in my routes. For example,
if(this.get('session.isAuthenticated')){
this.transitionTo('messages');
}
Have you injected the session into your controller?
I apologize. I actually think that now, the best thing to do would be to figure out how to get the belongsTo, hasMany relationship working between message and user. I’ll take any advice you have regarding that
Also I was able to get this to work with
let sessionName = get(this,'session.currentUser.email');
and then assigning sessionName to the new message’s user
Please also include your user and message models.