Skip to content

Latest commit

 

History

History
118 lines (95 loc) · 2.65 KB

File metadata and controls

118 lines (95 loc) · 2.65 KB

Open Signup

Guide to the Open Signup plugin, including public registration flow, installation, basic setup, and optional email verification.

Open Signup

Open Signup plugin allows users to register in adminforth by them-selfs without admin. This is useful when you want to allow anyone to sign up and assign some low-level permissions to them.

Installation

To install the plugin:

pnpm add @adminforth/open-signup --save

Usage

To use the plugin, instantiate to to user resource:

import OpenSignupPlugin from '@adminforth/open-signup';

Like this:

new OpenSignupPlugin({
    emailField: 'email',
    passwordField: 'password',
    passwordHashField: 'password_hash',
    defaultFieldValues: {
      role: 'user',
    },
    expectedOrigin: process.env.OPEN_SIGHNUP_ORIGIN || 'http://localhost:3500',
  }),

Please note that in this mode users will be able to sign up without email verification. For enabling email verification, see below.

Email verification

First, you need to migrate the adminuser table in ./schema.prisma:

model adminuser {
  ...
  //diff-add
  email_confirmed Boolean? @default(false)
}

And prisma migrate:

pnpm makemigration --name add-email-confirmed-to-adminuser ; pnpm migrate:local

Next, install the @adminforth/email-adapter-aws-ses package:

pnpm add @adminforth/email-adapter-aws-ses --save

Also, update the resource configuration in ./resources/adminuser.ts:

...
//diff-add
import EmailAdapterAwsSes from '@adminforth/email-adapter-aws-ses';

export default {
  dataSource: 'maindb',
  table: 'adminuser',
  resourceId: 'adminuser',
  label: 'Users',
  recordLabel: (r) => `👤 ${r.email}`,
  columns: [
    ...
    //diff-add
    { name: 'email_confirmed' }
  ],
  ...
  plugins: [
    ...
    new OpenSignupPlugin({
      emailField: "email",
      passwordField: "password",
      passwordHashField: "password_hash",
      defaultFieldValues: {
        role: "user",
      },
      //diff-add
      confirmEmails: {
        //diff-add
        emailConfirmedField: "email_confirmed",
        //diff-add
        sendFrom: "no-reply@devforth.io",
        //diff-add
        adapter: new EmailAdapterAwsSes({
          //diff-add
          region: "eu-central-1",
          //diff-add
          accessKeyId: process.env.AWS_ACCESS_KEY_ID as string,
          //diff-add
          secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY as string,
          //diff-add
        }),
        //diff-add
      },
    }),
    ...
  ],
  ...
}