Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send magic link after user registrated #73

Closed
no1-knows opened this issue Jan 18, 2020 · 7 comments
Closed

How to send magic link after user registrated #73

no1-knows opened this issue Jan 18, 2020 · 7 comments

Comments

@no1-knows
Copy link

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

@no1-knows
Copy link
Author

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)

@mikker
Copy link
Owner

mikker commented Jan 22, 2020

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

@no1-knows
Copy link
Author

no1-knows commented Jan 27, 2020

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
Copy link
Author

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

@fa11enangel
Copy link

fa11enangel commented Sep 9, 2020

This is wrong

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

@mikker
Copy link
Owner

mikker commented Sep 9, 2020

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

@fa11enangel
Copy link

fa11enangel commented Sep 9, 2020

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.

@mikker mikker closed this as completed Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants