I'm using omniauth and devise and google to have users login to the website. I need to only allow users to sign in if they have a specific company email. For example, they click on sign-in with google and then unless they have a "@somecompany.com" email address they can successfully login. Otherwise they cannot login with a normal "@gmail.com" email. I cant seem to find where to do that in the documentation.
user model
def self.from_omniauth(access_token)
data = access_token.info
user = User.where(email: data['email']).first_or_initialize
user.given_name = data['first_name']
user.family_name = data['last_name']
user.password = SecureRandom.uuid
user.save!
user
end
omniauth controller
def google_oauth2
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.google_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
routes
devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }