Magic link

Login without Password

To allow your members to log in without a password, just by providing their email you can use the magic-link-auth method provided by the Klub plugin. You will need to enable it in the config.

The default Kirby login form will change from "email + password" to just "email".

site/config/config.php
<?php

return [
  'auth' => [
        'methods' => ['code', 'magic-link'],
   ],
  // other options
];

Custom Login Form

Instead of using the login form from Kirby intended for Panel users, you should consider creating your own. The Klub plugin provides both the endpoints to start the authentication (send the email) and log in after clicking on the magic link.

site/snippets/account-login-magic.php
<form action="<?= site()->url() ?>/klub/magic-link" method="POST">
    <input type="email" name="email" required 
           placeholder="Email"
           value="<?= get('email') ?>">
    <input type="hidden" name="redirect" value="<?= $page->url() ?>">
    <input type="hidden" name="token" value="<?= csrf() ?>">
    <button type="submit">Login Link</button>
</form>

Instead of using the login form with email and password, it is also possible to send the member an email with a magic link to log in without a password. The same process can also be used for the initial signup.

You can also provide a success_url to which the new member will be redirected after being logged in via the magic-link.

site/snippets/account-signup-magic.php
<form action="<?= site()->url() ?>/klub/signup" method="POST">
    <input type="hidden" name="token" value="<?= csrf() ?>">
    <input type="hidden" name="redirect" value="<?= site()->url() ?>">
    <input type="email" name="email" required
           placeholder="Email"
           value="<?= get('email') ?>">
    <input type="text" name="name" required
           placeholder="Name"
           value="<?= get('name') ?>">
    <input type="hidden" name="success_url"
           value="<?= page('demo')->url() ?>?status=welcome">
    <button type="submit">Signup with magic link</button>
</form>
Kirby Klub is not affiliated with the developers of Kirby CMS. We are merely standing on the shoulder of giants.
© 2024 Bruno Meilick All rights reserved.