I wanna create a login with facebook without using the gem. By using facebook-sdk i am getting autoResponse: accessToken and userID
. Now I need to sign_up in my rails app on after success event FB.Login.
Please suggest how to achieve this?
Thanks
Create a table to store the details that you get from facebook. On sucessful facebook signin save them to that table and then create a user using those details keep an association like
facebook_details belongs to user
user has many facebook_details
Using those associations create a user
You could create a table called social_logins
, and assuming you have users
table, you can build a has_many
association b/w them, like user
has_many social_logins
, and in the social_logins
table you could have a type
column, which would store facebook
, in the near future, if you want to implement let's say login with twitter
or google
, you can make use of type
column and every other information could be stored in social_logins
table.
class User < Activerecord::Base
has_many :social_logins
end
class SocialLogin < Activerecord::Base
belongs_to :user
end
Make sure social_logins
table contains type
column, and other columns such as authToken
, user_id
and any other additioanl information you want related to social_login. You can also make use of additional data, such as first_name
, last_name
, and so on, and create a User
(Sign up).
Steps you will have to do.
Login with Facebook
. email
and password
. rails
check if the user with that email
exists, if he does not, create
the user
and use the additional information you got in the response to sign up the user and log
him into the application
. Login with Facebook
, enters his email
and password
, check if the user exists in DB, he does, so log him into the application directly. Login
using Facebook
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.