这是我的自定义注册控制器:
class RegistrationsController < Devise::RegistrationsController
def create
build_resource
if resource.valid? && resource.save_with_subscription
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in resource_name, resource
WelcomeMailerWorker.perform_async(resource.id)
return render json: { success: true, path: after_sign_up_path_for(resource) }
else
clean_up_passwords(resource)
return render json: { success: false, errors: resource.errors.full_messages.to_sentence }
end
end
def destroy
current_user.soft_delete
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
set_flash_message :notice, :destroyed if is_navigational_format?
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
end
def after_sign_up_path_for(resource)
return finalize_profile_path if resource.athlete?
return root_path if resource.college_coach?
end
def check_username
@user = User.find_by_username(params[:username])
return render text: @user.nil?
end
end
路线:
devise_for :users, skip: :registrations, controllers: { sessions: "sessions", passwords: "passwords" }
devise_for :athletes, skip: [:sessions, :passwords], controllers: { registrations: "registrations" }
devise_for :coaches, skip: [:sessions, :passwords], controllers: { registrations: "registrations" }
当用户被重定向到 时finalize_profile_path
,该authenticate_user!
方法由于某种原因返回 401 未授权
我做了一些进一步的调试,似乎 Devise 在注册后根本没有登录用户