You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I started with just devise and now am integrating this gem and ng-token-auth. I got sign in working, but for sign up, the API constantly returns email is not unique, when I can create a new user in the console with exact credentials.
UserRegistrationsController registration form submit function
I am customizing the registration controller because I need to gate users with a code for private beta release, so I set a custom route to point to the controller:
routes.rb
namespace 'api' do
scope 'v1' do
mount_devise_token_auth_for 'User', at: 'auth', defaults: {format: :json}, controllers: {
....
registrations: 'token_auth_override/registrations', #CUSTOM
....
}
end
end
I am setting the strong params in the application_controller, as recommended in the docs both here and devise:
application_controller.rb
class ApplicationController < ActionController::Base
include ActionController::MimeResponds
protect_from_forgery
respond_to :html, :json
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:alias, :invite_code, :first_name, :last_name, :email, :password, :password_confirmation, :bio, :youtube_url, :personal_url, :twitter_url, :facebook_url, :user_profile_pic, :provider) }
end
end
registration request from the client hit this controller in
token_auth_override/registrations_controller.rb
class TokenAuthOverride::RegistrationsController < DeviseTokenAuth::RegistrationsController
include DeviseTokenAuth::Concerns::SetUserByToken
before_action :configure_permitted_parameters, if: :devise_controller?
respond_to :json
def create
invite_code = SignUpCode.find_by_code_string(params[:invite_code])
if invite_code && invite_code.active?
@user = User.new(
email: params[:email],
first_name: params[:first_name],
last_name: params[:last_name],
provider: params[:provider],
password: params[:password],
password_confirmation: params[:password_confirmation]
)
@user.level = invite_code.level
if @user.save
# sign user in
sign_in(@user)
invite_code.increment
respond_to do |format|
format.json { render json: @user }
end
else
render json: {
status: 'error',
errors: @user.errors,
data: @user,
valid: @user.valid?
}, status: 403
end
else
# message that code is invalid
respond_to do |format|
format.json { render json: {message: 'Invite code invalid'}, status: :precondition_failed }
end
end
end
end
json response looks something like this:
data: {id: null, email: "test12312@test.com", created_at: "2015-05-01T23:21:04.492Z",…}
errors: {email: ["This email address is already in use"]}
status: "error"
valid: false
Oddly, if i remove include DeviseTokenAuth::Concerns::User in my user.rb model, I do not run into this error. I'd be happy to provide any additional snippets.
Thanks in advance for any help/thoughts. Been struggling to get this working for a while now...
The text was updated successfully, but these errors were encountered:
Hello,
I started with just devise and now am integrating this gem and ng-token-auth. I got sign in working, but for sign up, the API constantly returns email is not unique, when I can create a new user in the console with exact credentials.
UserRegistrationsController registration form submit function
I am customizing the registration controller because I need to gate users with a code for private beta release, so I set a custom route to point to the controller:
routes.rb
I am setting the strong params in the application_controller, as recommended in the docs both here and devise:
application_controller.rb
registration request from the client hit this controller in
token_auth_override/registrations_controller.rb
json response looks something like this:
Oddly, if i remove
include DeviseTokenAuth::Concerns::User
in my user.rb model, I do not run into this error. I'd be happy to provide any additional snippets.Thanks in advance for any help/thoughts. Been struggling to get this working for a while now...
The text was updated successfully, but these errors were encountered: