๐ชMagic Link Signup
Who likes passwords? Easily setup magic link in your LightningRails app.

If you want to increase your signups, ditching the password is the best way.
Config
If it hasn't been done yet, make sure that the environment is set to the correct email delivery method:
Model
To send Magic links, generate an instance of a magic Link with a unique token, think of it as an invitation instance:
Migrate:
In your model file email_link.rb
In your user.rb file
Generate Mailer
In the model we are creating a send_mail method, now we define it in our mailer method:
This should generate email_link_mailer.rb a few other files, in this mailer file, add this code:
Let's create the view file:
Now let's write a nice welcome email, no need to go above the board, the user just needs a link to sign up:
Route
We will need new routes to make this work.
Controller
We will also need a new controller.
In the controller, we will add these methods. One method to create the new link, and one to validate that the link is correct, the latter will be linked directly in the email.
Views
The last thing we have to do is go to the new sessions path and replace the existing form with this new one:
This form will work for both Signup and Login, so no need to do the same setup in registrations. Just change all the signup links to redirect to sessions/new by default.
The reason I recommend adding the sessions new instead of registration is that the authenticated_user method redirects to sessions, so you can reuse that feature with your new magic link ๐
Happy Magic linking! ๐ฆ
Last updated
Was this helpful?