mikker / passwordless

🗝 Authentication for your Rails app without the icky-ness of passwords
MIT License
1.27k stars 88 forks source link

Error when registering new users #175

Closed keilmillerjr closed 11 months ago

keilmillerjr commented 11 months ago

source "https://rubygems.org" passwordless (1.0.0) rails (7.1.1)

I could use help. I am not sure if I am doing something wrong, or this is a bug. User is created, but I get an error when trying to sign them in automatically. See documentation Registering new users. Thank you in advance.

ActiveRecord::ActiveRecordError in UsersController#create
Cannot touch on a new or destroyed record object. Consider using persisted?, new_record?, or destroyed? before touching.

Extracted source (around line #19):
17
18  if @user.save
19    sign_in(build_passwordless_session @user)
20    redirect_to root_path, success: 'Welcome aboard!'
21  else
22    flash[:error] = @user.errors.full_messages
class UsersController < ApplicationController
invisible_captcha only: [:create], honeypot: :last_name

  def index
    @users = User.all
  end

  def new
    @user = User.new
  end

  def edit
  end

  def create
    @user = User.new user_params

    if @user.save
      sign_in(build_passwordless_session @user)
      redirect_to root_path, success: 'Welcome aboard!'
    else
      flash[:error] = @user.errors.full_messages
      render :new
    end
  end

  private

  def user_params
    params.require(:user).permit(:email, :name)
  end
end
mikker commented 11 months ago

Hi! Try using the create_passwordless_session helper instead? This may be an error in the docs

mikker commented 11 months ago

Updated the README

keilmillerjr commented 11 months ago

Updated the README

https://github.com/mikker/passwordless/commit/a7891a8be98cf9f4771155ac470b6811e660c473

All is well with the cosmos.