Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues using devise and devise_token_auth #159

Closed
davegreco opened this issue Feb 21, 2015 · 4 comments
Closed

Issues using devise and devise_token_auth #159

davegreco opened this issue Feb 21, 2015 · 4 comments

Comments

@davegreco
Copy link

When I attempt to perform a sign up using devise I get the error "uid can't be blank" when validating the creation of a new user. I suspect that this is due to me being forced to use omniauth. I included the omniauth gem in order to get the project to even compile, the instructions for excluding it do not appear to work. Does devise handle registrations differently than devise_token_auth when it comes to registering? I even tried adding :omniauthable to my user model. What is supposed to happen when you register with just a username and a password when :omniauthable is set? Everything that I'm seeing indicates that you should be able to, does devise_token_auth force a uid to be present where devise would not? Do I need to modify the devise controller to populate uid with the e-mail or something? Any help here would be greatly appreciated, the gem looks very promising compared to alternative solutions but unfortunately I need devise to work normally in it's own /users namespace for the admin part of this site and the /auth to work with in my /api namespace for a mobile app to interface with (which it appears to nicely) but it renders the admin site useless as you can't register or sign in using the devise gem. I understand that this is supported by the community so mileage may vary but if anyone has input I could use it ASAP.

Also, when using both devise and devise_token_auth user_signed_in? in a template results in the following error:

ArgumentError in Devise::Registrations#create
Showing /.../app/views/shared/_header.erb where line #31 raised:

wrong number of arguments (1 for 0)

user_signed_in? works on every other controller other than devise controllers, the same happens at #new

@ACPK
Copy link

ACPK commented Feb 23, 2015

@davegreco - You need to set the "provider" param to "email" if you're using the devise gem with the devise token database. Let me know how that works for you!

@vic700208
Copy link

In regards to the "wrong number of arguments (1 for 0)" error, I managed to fix the issue by moving
include DeviseTokenAuth::Concerns::SetUserByToken
to a sub controller, since there are several methods (like current_user) on both gems that overlap.

Example:

app/controllers/api/base_controller.rb

module Api
  class BaseController < ApplicationController
    include DeviseTokenAuth::Concerns::SetUserByToken
  end
end

config/routes.rb

  namespace :api, defaults: {format: :json} do
    scope :v1 do
      mount_devise_token_auth_for 'User', at: 'auth', skip: [:omniauth_callbacks]
    end
  end

@vic700208
Copy link

In regards to the "uid can't be blank" error, just add the following to the user model:

app/models/user.rb

  before_validation do
    self.uid = email if uid.blank?
  end

@lynndylanhurley
Copy link
Owner

@ACPK is right - the uid value will be set to the user's email if provider is set to "email".

The solution that @vic700208 will work as well unless you're using OmniAuth, in which case it will cause problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants