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

Unable to sign_in even if user confirmation is success #1285

Closed
nihp opened this issue May 4, 2019 · 2 comments
Closed

Unable to sign_in even if user confirmation is success #1285

nihp opened this issue May 4, 2019 · 2 comments

Comments

@nihp
Copy link

nihp commented May 4, 2019

These are the version specifications used in my application,

  • rails 5.2.3
  • ruby 2.6.2
  • devise_token_auth 1.1.0

During user registration with this endpoint,
http://localhost:3000/api/v1/auth/

I got the confirmation url as follows,
http://localhost:3000/api/v1/auth/confirmation?config=default&confirmation_token=GHz9m52xVeQJJLFLJnWw&redirect_url=%2F

When hitting the above confirmation url I could see "ConfirmationsController#show" method could called twice times. On an first time call it says confirmation gets success and on the second time call it throws an error as "[{:error=>:already_confirmed}]}>" then this leads to routing error,

Logs:

_Started GET "/api/v1/auth/confirmation?config=default&confirmation_token=GHz9m52xVeQJJLFLJnWw&redirect_url=%2F" for ::1 at 2019-05-04 14:45:46 +0530_
Processing by DeviseTokenAuth::ConfirmationsController#show as HTML
  Parameters: {"config"=>"default", "confirmation_token"=>"GHz9m52xVeQJJLFLJnWw", "redirect_url"=>"/"}
  User Load (0.7ms)  SELECT  "users".* FROM "users" WHERE "users"."confirmation_token" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["confirmation_token", "GHz9m52xVeQJJLFLJnWw"], ["LIMIT", 1]]
  ↳ /home/user/.rvm/gems/ruby-2.6.2@church/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
   (0.3ms)  BEGIN
  ↳ /home/user/.rvm/gems/ruby-2.6.2@church/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
  User Update (0.7ms)  UPDATE "users" SET "confirmed_at" = $1, "updated_at" = $2 WHERE "users"."id" = $3  [["confirmed_at", "2019-05-04 09:15:46.325684"], ["updated_at", "2019-05-04 09:15:46.326717"], ["id", 26]]
  ↳ /home/user/.rvm/gems/ruby-2.6.2@church/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
   (1.4ms)  COMMIT
  ↳ /home/user/.rvm/gems/ruby-2.6.2@church/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
Redirected to http://localhost:3000:///?account_confirmation_success=true
Completed 302 Found in 21ms (ActiveRecord: 3.1ms)

_Started GET "/api/v1/auth/confirmation?config=default&confirmation_token=GHz9m52xVeQJJLFLJnWw&redirect_url=%2F" for ::1 at 2019-05-04 14:45:46 +0530_
Processing by DeviseTokenAuth::ConfirmationsController#show as HTML
  Parameters: {"config"=>"default", "confirmation_token"=>"GHz9m52xVeQJJLFLJnWw", "redirect_url"=>"/"}
  User Load (0.7ms)  SELECT  "users".* FROM "users" WHERE "users"."confirmation_token" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["confirmation_token", "GHz9m52xVeQJJLFLJnWw"], ["LIMIT", 1]]
  ↳ /home/user/.rvm/gems/ruby-2.6.2@church/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
Completed 404 Not Found in 6ms (ActiveRecord: 0.7ms)

ActionController::RoutingError (Not Found):

devise_token_auth (1.1.0) app/controllers/devise_token_auth/confirmations_controller.rb:30:in show' actionpack (5.2.3) lib/action_controller/metal/basic_implicit_render.rb:6:in send_action'

When sign_in with this url,
http://localhost:3000/api/v1/auth/sign_in
I got the response as,

{
    "success": false,
    "errors": [
        "A confirmation email was sent to your account at '[email protected]'. You must follow the instructions in the email before your account can be activated"
    ]
}

Questions,

  1. Why "ConfirmationsController#show" called twice a time when hitting confirmation url?
  2. Why the user has not able to sign_in even if confirmation gets success?

What I missed here?

@kamenomagic
Copy link

You have confirmable on in your user's model I think. So you must click confirm in your email before you can log in. (I think).

For testing you can just turn :confirmable off in your user model (comment it out cause you probably want it later)

@jattoabdul
Copy link

I need help with this too. I am using mailcatcher to catch emails in development env. What I realized is, when I set a default_confirm_success_url in the devise_token_auth.rb config file, I get this behaviour explained by @nihp , but when I comment that global default config default_confirm_success_url and pass confirm_success_url to the sign_up route, I get the right behaviour, it creates the account, sends the email and mailcatcher catches it and when clicked it does the redirect to the URL specified.

Why the weird behaviour when setting as default config for confirm_success_url in the config file?

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

No branches or pull requests

4 participants