twitter-4 selections of certain errors with Twitter login function created by omniauth gem and how to deal with them

Here are four errors and how to deal with them when implementing the user management function by Twitter login in Ruby On Rails.

Email address verification

Use the devise gem as the base for user management features. Use the omniauth-twitter gem to create the Twitter login function.

Gemfile


gem 'devise' 
gem 'omniauth' 
gem 'omniauth-twitter'
bundle install

reference: Send an email when registering with devise Procedure to implement user authentication with Devise + OmniAuth in Rails

Error 1: I get an error when I try to sign up

NameError in Devise::RegistrationsController#create\_ \_undefined local variable or method \`confirmed\_at' for #User: Did you mean? confirmed?

Solution

Add the #confirmable column to the User model

user.rb


devise :confirmable

Error 2: Missing host to link to!

Missing host to link to! Please provide the :host parameter, set default\_url\_options\[:host\], or set :only\_path to true\_ 

Solution

Specify the host url in config> environment> development.rb

/config/environments/development.rb


  host = 'samplehost'
  Rails.application.routes.default_url_options[:host] = host

Reference: When Missing host to link to! Appears in Rails. Settings when assembling URLs in model

Error 3: After pressing the new registration / login button, the devise login screen is displayed again (returns to the login page).

This is an error due to the user information not being registered in the DB.

Solution

  1. Insert the process to set the email address automatically Reference: Record is not stored even if twitter authentication of omniauth is completed in Devise
  2. Ignore email addresses in the first place Reference: Why persist? Is false.
  3. There is a pattern such as removing: validatable from devise.rb. Reference: [devise / omniauth login with twitter --validation failed: email can't be blank](https://stackoverflow.com/questions/10374827/devise-omniauth-login-with-twitter-validation-failed-email-cant] -be-blank)

1 is recommended.

Error 4: User ID cannot be obtained

undefined method \`id' for nil:NilClass 

Error cause: You cannot log in and your user ID is null. Reference: undefined method ʻid'for nil: About NilClass

Solution

Check if current_user has a value

Recommended Posts

twitter-4 selections of certain errors with Twitter login function created by omniauth gem and how to deal with them
Common problems with WSL and how to deal with them
[Ruby] 5 errors that tend to occur when scraping with Selenium and how to deal with them
How to deal with different versions of rbenv and Ruby
Java8 / 9 Beginners: Stream API addiction points and how to deal with them
How to boot by environment with Spring Boot of Maven
How to deal with the error ERROR: While executing gem ... (Gem :: FilePermissionError)
How to deal with Bundler :: Dsl :: DSLError by rewriting gemfile
How to use the certificate and private key created by Docker's BASIC authentication with AWS ALB
[Swift] How to implement the Twitter login function using Firebase UI ①
[Swift] How to implement the Twitter login function using Firebase UI ②
[Rails] Implementation procedure of the function to tag posts without gem + the function to narrow down and display posts by tags
[Node.js express Docker] How to define Docker environment variables and load them with node.js
Analyzing and visualizing csv logs with Excel Elastic Stack (docker-compose) --How to deal with data duplication errors in Elasticsearch