I never thought it is possible to authenticate with social media account before email validation.
I've been doing automated merging of social media accounts with the user profile in my app, if email addresses are matching. E.g. if a user signs up as [email protected], and then someone else signs in using Twitter OAuth provider, using Twitter account with the same email, Twitter identity will be merged with the application profile.
Now I need to fix the related use case.
I think most services confirm your email, but I don't know for sure if they force you to do that before using OAuth. It's definitely something to think about. Automatic merging is probably okay so long as you can trust that those accounts were already confirmed. I'm just not 100% that they are. I would guess that every service is different so it's probably safest not to auto-merge. If you find out more details on that, let us know!
Hi Chris Oliver,
I keep getting the following error "You cannot call create unless the parent is saved" on line 25 of the omniauth_callbacks_controller.rb
Was this working correctly with yours?
So that error is a result of calling create on your service instance when the user it's associated to hasn't been saved to the database. I resolved this by creating by calling find_or_initalize_by on the user model, checking if that record was valid, and then calling save! on the record.
Make sure your User validations are passing. We only validate the email and password in this example so if you've required other fields, your User won't be saved.
Okay, found the issue. It failed as Twitter don't give you a user e-mail so it fails on the validation of that one. So i just took care of that case and now it's working but maybe you can review this in one of the episodes how to handle these cases. Especially with the GDPR where a confirmed E-Mail is required.
First off thank you kindly for this tutorial, it helped me a lot with my school project.
Now, down to business.
I have integrated the authentication and devise which all works like a charm.
So heres my new issue:: i want t make a post on my app and send it to multiple services and save it to my databse.
i have a Post model, which creates a post on my app and saves to database, but i want to take that post and broadcast it to twitter(and eventually facebook)
do i put the twitter::Rest::Client.new mehtod in the service model under the twitter method? seems like the likely candidate, but a little confused as goRails episode 33 uses it in the User model, which we have on this guide as the omniauth callback controller.
then i was thinking of using boolean logic to check if user.service.provider == twitter run the post_to_twitter method.
any feedback would be great :)