passwordless icon indicating copy to clipboard operation
passwordless copied to clipboard

How to send magic link after user registrated

Open no1-knows opened this issue 5 years ago • 7 comments

Is there any way to send magic link after user registered like sign_in @user for security?

no1-knows avatar Jan 18 '20 12:01 no1-knows

Did I make myself clear? Let me explain more.

I would like to make the flow, from signup to signin, like slack. The flow like below.

  1. Input email for signup.
  2. check email and click.

Could you let me know how to do this? I think it will work if I could use module Passwordless properly...but I didn't.

As far as I know, this gem has 2 flows.

First: It is a pain in input twice.

  1. Input email for signup.
  2. Input email for signin.
  3. check email and click.

Second: It is not good for security because the email might not valid.

  1. Input email for signup and signin.(using sign_in @user)

no1-knows avatar Jan 22 '20 11:01 no1-knows

Something like this...

# registrations_controller.rb
include Passwordless::ControllerHelpers

def create
  user = User.new(email: params[:email])

  if user.save
    pwless_session = build_passwordless_session(user)
    pwless_session.save!

    YourOwnRegistrationsMailer.signup(token: pwless_session.token).deliver_now
    # ... redirect back or whatever
  end
end

mikker avatar Jan 22 '20 12:01 mikker

Thank you for your help!! I did it like below!

def create
  @user = User.new(user_params)

    respond_to do |format|

      if @user.save
        pwless_session = build_passwordless_session(@user)
        pwless_session.save!
        RegistrationMailer.with(token: pwless_session.token, user: @user).welcome_email.deliver_now
        # ... redirect back or whatever
  end
end

no1-knows avatar Jan 27 '20 21:01 no1-knows

I want you to add this way at README.md if you can. Anyway, please enjoy a cup of coffee, maybe for one year!!

no1-knows avatar Jan 28 '20 01:01 no1-knows

This is wrong

I've deleted the message due to wrong content - some local issue on my machine.

fa11enangel avatar Sep 09 '20 09:09 fa11enangel

I'm not sure that's right. save! calls callbacks: https://guides.rubyonrails.org/active_record_callbacks.html#running-callbacks

mikker avatar Sep 09 '20 11:09 mikker

You are right, but this is a case for my small test project using your gem. I'll create a new issue with all information.

fa11enangel avatar Sep 09 '20 11:09 fa11enangel