ByeSeeChairTen

payload magic login

by ByeSeeChairTen
Authentication & SSO
v2
^2.0.0
MIT

Overview

Summary generated from the README

Adds email-based magic link login to Payload. Links are signed with a JWT secret and sent through Payload's email configuration to targets such as the admin panel or a mobile app deep link. The plugin currently creates its own user collection with email and salt/hash, and it requires email transport options and a server URL in the config. It targets Payload 2.x and is marked as under active development.

Features

  • Sends login links by email using the Payload email configuration
  • Signs links with JWTs using a configurable secret
  • Defines multiple targets with custom URI, subject and HTML template
  • Supports deep links to apps as well as the admin panel
  • Can be enabled or disabled through a plugin option

Use cases

  • Let mobile app users sign in through an emailed link instead of a password
  • Offer passwordless sign-in for admin users on a Payload 2.x project

From the author

A Magic Login plugin for Payload CMS

Installation

npm i payload-magic-login

3

Stars

0

Forks

1

Open Issues

2 years ago

Last Updated

25

Weekly Downloads

v1.1.0

npm Version

122.6 KB

Unpacked Size

3

Dependencies

GitHub stars

30 since Sep 7

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 20263
Dec 5, 20263
Dec 4, 20263
Dec 3, 20263
Dec 2, 20263
Dec 1, 20263
Nov 30, 20263
Nov 29, 20263
Nov 28, 20263
Nov 27, 20263
Nov 26, 20263
Nov 25, 20263
Nov 24, 20263
Nov 23, 20263
Nov 22, 20263
Nov 21, 20263
Nov 20, 20263
Nov 19, 20263
Nov 18, 20263
Nov 17, 20263
Nov 16, 20263
Nov 15, 20263
Nov 14, 20263
Nov 13, 20263
Nov 12, 20263
Nov 11, 20263
Nov 10, 20263
Nov 9, 20263
Nov 8, 20263
Nov 7, 20263
Nov 6, 20263
Nov 5, 20263
Nov 4, 20263
Nov 3, 20263
Nov 2, 20263
Nov 1, 20263
Oct 31, 20263
Oct 30, 20263
Oct 29, 20263
Oct 28, 20263
Oct 27, 20263
Oct 26, 20263
Oct 25, 20263
Oct 24, 20263
Oct 23, 20263
Oct 22, 20263
Oct 21, 20263
Oct 20, 20263
Oct 19, 20263
Oct 18, 20263
Oct 17, 20263
Oct 16, 20263
Oct 15, 20263
Oct 14, 20263
Oct 13, 20263
Oct 12, 20263
Oct 11, 20263
Oct 10, 20263
Oct 9, 20263
Oct 8, 20263
Oct 7, 20263
Oct 6, 20263
Oct 5, 20263
Oct 4, 20263
Oct 3, 20263
Oct 2, 20263
Oct 1, 20263
Sep 30, 20263
Sep 29, 20263
Sep 28, 20263
Sep 27, 20263
Sep 26, 20263
Sep 25, 20263
Sep 24, 20263
Sep 23, 20263
Sep 22, 20263
Sep 21, 20263
Sep 20, 20263
Sep 19, 20263
Sep 18, 20263
Sep 17, 20263
Sep 16, 20263
Sep 15, 20263
Sep 14, 20263
Sep 13, 20263
Sep 12, 20263
Sep 11, 20263
Sep 10, 20263
Sep 9, 20263
Sep 8, 20263
Sep 7, 20263
npm weekly downloads

26+17 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202626
Dec 5, 202619
Dec 4, 20262
Dec 3, 20264
Dec 2, 20266
Dec 1, 202610
Nov 30, 202617
Nov 29, 202634
Nov 28, 202635
Nov 27, 202638
Nov 26, 202636
Nov 25, 202634
Nov 24, 202632
Nov 23, 202625
Nov 22, 20269
Nov 21, 20269
Nov 20, 20266
Nov 19, 20269
Nov 18, 202616
Nov 17, 202614
Nov 16, 202615
Nov 15, 202613
Nov 14, 202614
Nov 13, 202616
Nov 12, 202621
Nov 11, 202614
Nov 10, 202614
Nov 9, 202614
Nov 8, 202615
Nov 7, 202613
Nov 6, 202610
Nov 5, 20263
Nov 4, 20263
Nov 3, 20264
Nov 2, 20268
Nov 1, 20269
Oct 31, 202623
Oct 30, 202631
Oct 29, 202630
Oct 28, 202630
Oct 27, 202630
Oct 26, 202627
Oct 25, 202625
Oct 24, 202612
Oct 23, 20264
Oct 22, 20265
Oct 21, 20267
Oct 20, 20266
Oct 19, 20264
Oct 18, 20264
Oct 17, 20264
Oct 16, 20265
Oct 15, 20265
Oct 14, 20263
Oct 13, 20263
Oct 12, 20263
Oct 11, 20264
Oct 10, 20263
Oct 9, 20262
Oct 8, 20261
Oct 7, 20261
Oct 6, 20261
Oct 5, 20261
Oct 4, 20263
Oct 3, 20263
Oct 2, 20264
Oct 1, 20267
Sep 30, 20267
Sep 29, 202615
Sep 28, 202615
Sep 27, 202613
Sep 26, 202616
Sep 25, 202615
Sep 24, 202613
Sep 23, 202613
Sep 22, 202615
Sep 21, 202617
Sep 20, 202617
Sep 19, 202616
Sep 18, 202616
Sep 17, 202616
Sep 16, 202617
Sep 15, 20267
Sep 14, 20268
Sep 13, 20267
Sep 12, 20266
Sep 11, 20266
Sep 10, 20265
Sep 9, 20265
Sep 8, 20269
Sep 7, 20269

Each point is npm's rolling 7-day download count.

Health Score

27/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/748450764-root.svg)](https://payloaddirectory.dev/plugins/748450764-root)
HTML
<a href="https://payloaddirectory.dev/plugins/748450764-root"><img src="https://payloaddirectory.dev/badge/748450764-root.svg" alt="Payload Directory"></a>
Updated Feb 5, 2024Created Jan 26, 2024Published Feb 5, 2024

README

Payload Magic Login Plugin

THIS IS A PACKAGE UNDER ACTIVE DEVELOPMENT - USE AT YOUR OWN RISK

This is built with the Payload CMS plugin template.

How to install this plugin

First install it with npm install payload-magic-login (or your preferred package manager).

To then install this plugin, simply add it to your payload.config() in the Plugin array.

import magicLoginPlugin from 'payload-magic-login';

export const config = buildConfig({
  plugins: [
    // You can pass options to the plugin
    magicLoginPlugin({
      secret: process.env.PAYLOAD_SECRET, // A secret used to sign the JWTs
      payload: payload, // Your payload instance
      enabled: true, 
      targets: [
         {
          target: "app-dev",
          uri: "exp://my-app-dev.exp.direct",
          subject: "GetRekd: Login Link",
          html: (link) => `Click this link to finish logging in: <a href="${link}">LOGIN LINK</a>, if you can't click the link, copy and paste this link into your browser: \n\n${link}`
        },
      ]
    })
  ]
});
It depends on these things in your config:
  // payload.config.ts
  ...
  email: {
    fromName: 'Oscar - GetRekd app',
    fromAddress: '[email protected]',
    // You can use the ethereal mail in dev, 
    // but requires some sort of transport options for actual emails (See Payload Docs)
    transportOptions: {
      host: process.env.SMTP_HOST,
      auth: {
        user: process.env.SMTP_USER,
        pass: process.env.SMTP_PASS,
      },
      port: process.env.SMTP_PORT,
      secure: Number(process.env.SMTP_SECURE) === 465,
      requireTLS: Number(process.env.SMTP_SECURE) === 587,
    }
  },
  // It will redirect to this URL
  serverURL: process.env.SERVER_URL || 'http://localhost:3000',
  ...
Things to consider

At this moment, it creates a user collection for you - with an email and salt/hash (plan is to support this alongside local auth, working on that). I will add support to extend this or have it update the given collection at a later date.

Example

In the dev folder, you’ll find a basic payload project, created with npx create-payload-app.

The magicLoginPlugin has already been installed to the payload.config() file in this project.

plugins: [
  magicLoginPlugin({
      secret: process.env.PAYLOAD_SECRET, // A secret used to sign the JWTs
      payload: payload, // Your payload instance
      enabled: true, 
      // Targets are used to determine where the link should point to.
      // For example: target: "admin" (default) creates a link to the admin panel.
      // The targets "app" and "app-dev" could be for opening the link in an app.
      targets: [
        {
          target: "app",
          uri: "exp://my-app.exp.direct",
          subject: "GetRekd: Login Link",
          html: (link) => `Click this link to finish logging in: <a href="${link}">LOGIN LINK</a>, if you can't click the link, copy and paste this link into your browser: ${link}`
        },
        {
          target: "app-dev",
          uri: "exp://my-app-dev.exp.direct",
          subject: "GetRekd: Login Link",
          html: (link) => `Click this link to finish logging in: <a href="${link}">LOGIN LINK</a>, if you can't click the link, copy and paste this link into your browser: \n\n${link}`
        },
      ]
    })
]

When you’re ready to start development, navigate into this folder with cd dev

And then start the project with yarn dev and pull up http://localhost:3000/ in your browser.

Types.ts

These are the current types/options for the plugin.

export interface PluginTypes {
  /**
   * Enable or disable plugin
   * @default false
   */
  enabled?: boolean
  /**
   * Secret used to sign JWTs
   */
  secret: string
  /**
   * The payload instance
   * @default payload
   */
  payload: Payload
  /**
   * Your own custom targets:
   * @default []
   * @example
   * targets: [
   *  { 
   *   target: "app",
   *   uri: "exp://my-app.example.com",
   *   subject: "GetRekd: Login Link",
   *   html: `Click this link to finish logging in: <a href="${link}">LOGIN LINK</a>, if you can't click the link, copy and paste this link into your browser: ${link}`
   *  },
   *  {
   *   target: "admin",
   *   uri: "https://admin.getrekd.lol",
   *   subject: "GetRekd: Login Link",
   *   html: `Click this link to finish logging in: <a href="${link}">LOGIN LINK</a>, if you can't click the link, copy and paste this link into your browser: ${link}`
   *  }
   * ]
   */
  `targets?: Array<{ target: string, uri: string, subject: string, html: (link: string) => string }>`
}
Testing

I will implement tests shortlyTM.

Contribute

Feel free to submit PRs and suggestions, the code isn't perfect by any means and is provided as-is.

Similar plugins

payload magic login — Payload Directory