Persona

Persona is a collection of Lucid model mixins for common user account operations. In this guide, you will learn:

  • What modules Persona provides
  • How the mixin composition pattern works
  • What peer dependencies are required

Overview

User accounts share a set of predictable behaviors, like verifying email addresses, resetting passwords, enrolling in two-factor authentication, and linking social provider identities. Persona packages these behaviors as Lucid model mixins that you compose onto your User model.

Each module is independent. You can use email management without password management, or add TOTP later without touching your existing setup.

Modules

Persona provides four modules, each available as a separate import.

  • Email management (@adonisplus/persona/email) handles email verification flows using a two-column pattern, cryptographic tokens, and atomic email switching.
  • Password management (@adonisplus/persona/password) handles password reset flows with secure tokens and atomic password updates.
  • TOTP management (@adonisplus/persona/totp) handles two-factor authentication with authenticator app enrollment, QR codes, and recovery codes.
  • Social identity (@adonisplus/persona/social) handles OAuth provider identity linking with secure identity resolution, snapshot tracking, and account management. Works directly with @adonisjs/ally user objects.

Mixin composition

Persona uses the compose helper from AdonisJS to apply mixins to your model. Each mixin adds instance methods and static methods to the model class.

app/models/user.ts
import { UserSchema } from '#database/schema'
import { compose } from '@adonisjs/core/helpers'
import { withAuthFinder } from '@adonisjs/auth/mixins/lucid'
import { withManagedEmail } from '@adonisplus/persona/email'
import { withSocialIdentity } from '@adonisplus/persona/social'
import { withManagedPassword } from '@adonisplus/persona/password'

export default class User extends compose(
  UserSchema,
  withAuthFinder(),
  withManagedEmail(),
  withManagedPassword(),
  withSocialIdentity()
) {}

You do not need to declare columns on the model. Lucid auto-generates a Schema class by introspecting the database, and the model picks up its columns from there.

Peer dependencies

Persona requires the following peer dependencies.

@adonisjs/core
required ^7.0.0

The AdonisJS framework core.

@adonisjs/lucid
required ^22.0.0

The Lucid ORM for database operations and model mixins.

@adonisjs/ally
^6.0.0

Required only if you use the social identity module. Provides OAuth driver integrations for providers like Google and GitHub.

@adonisjs/session
^8.0.0

Used for flashing error messages to the session during content-negotiated error handling.

@adonisjs/i18n
^3.0.0

Used for translating error messages using the errors.* keys.

otpauth
^9.5.0

Required only if you use the TOTP management module. Generates and verifies time-based one-time passwords.

qrcode
^1.5.4

Required only if you use the TOTP management module. Generates QR codes for authenticator app enrollment.

Terms & License Agreement