Skip to main content

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:

./resources/adminuser.ts
import OpenSignupPlugin from '@adminforth/open-signup';

Like this:

./resources/adminuser.ts
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:

./schema.prisma
model adminuser {
...
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:

./resources/adminuser.ts
...
import EmailAdapterAwsSes from '@adminforth/email-adapter-aws-ses';

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