Note that there are some explanatory texts on larger screens.

plurals
  1. POOmniauth/MYSQL awkwardness in Rails
    primarykey
    data
    text
    <p>I am using 'omniauth' and 'omniauth-facebook' gem for Rails 3.2, with Ruby 2.0, Today I've encountered an awkward situation that I couldn't find any solution for. Every user was using the facebook login perfectly until this.</p> <p>My Routes</p> <pre><code># Facebook authentication match 'auth/:provider/callback' =&gt; 'sessions#create' </code></pre> <p>My session controller</p> <pre><code>class SessionsController &lt; ApplicationController def create user = User.from_omniauth(env["omniauth.auth"]) session[:user_id] = user.uid redirect_to user end .... </code></pre> <p>My session model</p> <pre><code>def self.from_omniauth(auth) where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user| user.provider = auth.provider user.id = auth.uid user.uid = auth.uid user.name = auth.info.name if !user.username user.username = auth.uid end user.username = auth.info.nickname user.email = auth.info.email user.gender = auth.extra.raw_info.gender user.is_admin = false user.picture = "http://graph.facebook.com/#{auth.uid}/picture?type=large&amp;height=324&amp;width=580" user.updated_at = auth.extra.raw_info.updated_time user.oauth_token = auth.credentials.token user.oauth_expires_at = Time.at(auth.credentials.expires_at) user.save! end end </code></pre> <p>Let me show you the awkward part. A user is authenticated, lets call it TESTUSER, but instead of his current id, Rails redirects and sets the Session id different from its original ID.</p> <pre><code> User Load (132.4ms) SELECT `users`.* FROM `users` WHERE `users`.`provider` = 'facebook' AND `users`.`uid` = 100006300277396 LIMIT 1 (129.6ms) BEGIN SQL (130.6ms) INSERT INTO `users` (`age`, `bio`, `created_at`, `email`, `experience`, `fat_percentage`, `gender`, `height`, `id`, `is_admin`, `location`, `mass`, `name`, `oauth_expires_at`, `oauth_token`, `password`, `picture`, `provider`, `salt`, `uid`, `updated_at`, `username`) VALUES (NULL, NULL, '2013-07-09 15:32:14', 'TESTUSER@yandex.com', NULL, NULL, 'male', NULL, 100006300277396, 0, NULL, NULL, 'Test User', '2013-09-07 06:49:53', 'CAAHrxXWCZBwsBAEtkOVHkTHC5bMPlr6Q9IbWRSCBLzfEZBmSwKZAtr9ebHCxjO4xStcg9tew90u9fhVl2cTcIx7za6nJYz4wuMQmx7UrQDQntT1nGVOFy87ctuDAHS1jQueV0KXC3MvkWGZCn9ccprzJ8w4pKP0ZD', NULL, 'http://graph.facebook.com/100006300277396/picture?type=large&amp;height=324&amp;width=580', 'facebook', NULL, 100006300277396, '2013-07-09 10:33:49', 'TESTUSER') Started GET "/users/100006300277396" for 88.248.139.159 at 2013-07-09 15:32:14 +0000 Processing by UsersController#show as HTML Parameters: {"id"=&gt;"100006300277396"} User Load (130.8ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 100006300277396 LIMIT 1 Completed 404 Not Found in 170ms ActiveRecord::RecordNotFound (Couldn't find User with id=100006300277396): app/controllers/users_controller.rb:17:in `show' </code></pre> <p>In the console it says that the user's ID is 100006300277396 but on the database it is set to 2147483647. </p> <p>I've found out that the MYSQL statement works perfectly well, but because ID was auto-increment before, it inserts the last auto incremented value to the database. Therefore, the problem is with database, do you see any error?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload