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:

npm install @adminforth/open-signup

Usage

To use the plugin, instantiate to to user resource:

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

Like this:

./resources/user.ts
new OpenSignupPlugin({
emailField: 'email',
passwordField: 'password',
passwordHashField: 'password_hash',
defaultFieldValues: {
role: 'user',
},
}),

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 users table in ./schema.prisma:

./schema.prisma
model users {
...
email_confirmed Boolean? @default(false)
}

And prisma migrate:

npx --yes prisma migrate dev --name add-email-confirmed-to-users

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

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

export default {
dataSource: 'maindb',
table: 'users',
resourceId: 'users',
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,
}),
},
}),
...
],
...
}