Optimus Pette
Optimus Pette

Reputation: 3400

ArgumentError: After create callback :send_on_create_confirmation_instructions has not been defined. devise_token_auth

I'm using devise_token_auth for authenticating a rails-api application. I have included these devise modules in my user model as shown below.

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :confirmable
end

The problem is when i do a POST request on the email registration endpoint, http://localhost:3000/auth with email, password and password_confirmation as params. It only succeeds once after a server restart. All subsequent requests to register an user fail with this error:

{
  "status": 500,
  "error": "Internal Server Error",
  "exception": "#<ArgumentError: After create callback     :send_on_create_confirmation_instructions has not been defined>",
  "traces": {
         ...
   }

This means I have to restart the server every time I want to register a user.

This is what I have in the Gemfile.

gem 'devise', github: "plataformatec/devise"
gem 'devise_token_auth', github: "lynndylanhurley/devise_token_auth"

EDIT

When I make any change in ApplicationController and save it. The request succeeds without restarting the server.

Upvotes: 1

Views: 1964

Answers (2)

priyanka yadav
priyanka yadav

Reputation: 81

After Adding this line: resource_class.skip_callback("create", :after, :send_on_create_confirmation_instructions)

Just perform the task

And add this line for setting the callback again. resource_class.set_callback("create", :after, :send_on_create_confirmation_instructions)

we need to set callback again after skipping it.

Upvotes: 0

Optimus Pette
Optimus Pette

Reputation: 3400

I have finally found a solution, the problem was this line in the create method of the RegistrationsController in the devise_token_auth:

# override email confirmation, must be sent manually from ctrl
    resource_class.skip_callback("create", :after, :send_on_create_confirmation_instructions) 

I don't know why i would want to skip sending confirmation instructions, while the behaviour i want is to send the confirmation automatically when a user is created.

So I created an override of RegistrationController's create method using information on controllers ovverride provided in devise_token_auth gem docs. In the override, I commented out the line and everything is working as expected.

Upvotes: 1

Related Questions