[RUBY] About errors during SNS authentication

Background

After implementing the wizard-style user registration function To add SNS authentication Made the necessary description in registrations_controller. (The user model has already been described.)

controller


class Users::RegistrationsController < Devise::RegistrationsController

#Partially omitted

def create
    if params[:sns_auth] == 'true'
      pass = Devise.friendly_token
      params[:user][:password] = pass
      params[:user][:password_confirmation] = pass
    end
    super                               #The description added so far to the SNS authentication implementation
    @user = User.new(sign_up_params)    #Description for wizard format from here
      unless @user.valid?
        render :new and return
      end
      session["devise.regist_data"] = {user: @user.attributes}
      session["devise.regist_data"][:user]["password"] = params[:user][:password]
      @profile = @user.build_profile
      render :new_profile
  end

#Partially omitted

end

error contents

When I try to make a new registration, the following error message appears.

AbstractController::DoubleRenderError in Users::RegistrationsController#create

Render or redirect is used multiple times in the same action! The content. Why is the process finished with and return after render? Will be. ..

Error cause

At the end of the description added to implement SNS authentication By super. (Super can evoke a method with the same name as the method that describes super in the inheriting class.)

The destination is as follows. (https://github.com/heartcombo/devise/blob/master/app/controllers/devise/registrations_controller.rb) Reference source

RegistrationsController


class Devise::RegistrationsController < DeviseController

#Partially omitted

def create
    build_resource(sign_up_params)

    resource.save
    yield resource if block_given?
    if resource.persisted?
      if resource.active_for_authentication?
        set_flash_message! :notice, :signed_up
        sign_up(resource_name, resource)
        respond_with resource, location: after_sign_up_path_for(resource)
      else
        set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      set_minimum_password_length
      respond_with resource
    end
  end

#Partially omitted

end

It seems that respond_with in this is the cause of the error. Because respond_with has the role of render and redirect. Therefore, I tried to render or redilect in the method called by super, but there is another render in the description after that. Which one? It is probable that an error occurred.

Recommended Posts

About errors during SNS authentication
About Spring Security authentication
SNS authentication using Rails google
Error when introducing SNS authentication
About self-introduction and common errors
About signature authentication with java 1st