An open-source entry in TopGit's GitHub warehouse: adonisjs/persona, 182 stars, JavaScript. Opinionated user management service for AdonisJs
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
AdonisJs is all about removing redundant code from your code base. This add-on tries to do the same.
What is Persona?
Persona is a simple, functional service to let you create, verify and update user profiles.
Persona is not for everyone; if your login system is too complex and relies on many factors, Persona is not for you. However, persona works great for most use cases.
What does it do?
Helps you register new users.
Generates email verification tokens.
Validates credentials on login.
On email change, sets the user account to a pending state and re-generates the email verification token.
Allows changing passwords.
Allows recovering forgotten passwords.
What does it NOT do?
Does not generate any routes, controllers or views for you.
Does not send emails. However, it emits events that you can use to send emails.
Does not create sessions or generate JWT tokens.
Setup
Run the following command to grab the add-on from npm:
adonis install @adonisjs/persona
# for yarn
adonis install @adonisjs/persona --yarn
Follow up by registering the provider inside the providers array:
An array of database columns that will be used as uids. If your system allows username and emails both, then simply add them to this array.
email
email
The field to be used as email. Every time a user changes the value of this field, their account will be set to the pending state.
password
password
The field to be used as password.
model
App/Models/User
The user model to be used.
newAccountState
pending
The default account state for new users.
verifiedAccountState
active
The account state for users after verifying their email address.
dateFormat
YYYY-MM-DD HH:mm:ss
Your database date format, required for determining if the token has been expired or not.
validationMessages
function
A function that returns an object of messages to be used for validation. The syntax is the same as Validator custom messages.
Constraints
There are some intentional constraints in place.
Only works with Lucid models.
The App/Models/User must have a relationship setup with App/Models/Token and vice-versa.
class User extends Model {
tokens () {
return this.hasMany('App/Models/Token')
}
}
class Token extends Model {
user () {
return this.belongsTo('App/Models/User')
}
}
User table must have a string column called account_status.
API
Let's go through the API of persona.
register(payload, [callback])
The optional callback is invoked with the original payload just before the user is saved to the database. You can use it if you need to attach any other properties to the payload.
The register method takes the user input data and performs the following actions on it.
Validates that all uids are unique.
Checks that email is unique and is a valid email address.
Makes sure the password is confirmed.
Creates a new user account with the account_status = pending.
Generates and saves an email verification token inside the tokens table.
Emits a user::created event. You can listen for this event to send an email to the user.
Make sure to use querystring module to encode the token when sending via Email.
The optional callback is invoked with the user instance just before the password verification. You can use it to check for userRole or any other property you want.
Verifies the user credentials. The value of uid will be checked against all the uids.
You can define a function inside the config/persona.js file, which returns an object of messages to be used as validation messages. The syntax is the same as Validator custom messages.
The validationMessages method gets an action parameter. You can use it to customize the messages for different actions. Following is the list of actions.
register
login
emailUpdate
passwordUpdate
Events emitted
Below is the list of events emitted at different occasions.
Event
Payload
Description
user::created
{ user, token }
Emitted when a new user is created
email::changed
{ user, oldEmail, token }
Emitted when a user changes their email address
password::changed
{ user }
Emitted when a user changes their password by providing the old password
forgot::password
{ user, token }
Emitted when a user asks for a token to change their password
password::recovered
{ user }
Emitted when a user's password is changed using the token
Exceptions raised
The entire API is driven by exceptions, which means you will hardly have to write if/else statements.
This is great, since Adonis allows managing responses by catching exceptions globally.
ValidationException
Raised when validation fails. If you are already handling Validator exceptions, you won't have to do anything special.
InvalidTokenException
Raised when a supplied token, to verify an email or reset password with, is invalid.
Custom rules
At times, you may want to have custom set of rules when registering or login new users. You can override following methods for same.
The code can be added inside the hooks file or even in the registeration controller.
The most recent commit recorded on adonisjs/persona was 5.5 years ago, based on the GitHub push timestamp. The repository has 23 forks — one of the better signals of community interest.
How many stars does adonisjs/persona have?
adonisjs/persona has 182 GitHub stars — refresh the page for the live number, or check github.com/adonisjs/persona. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is adonisjs/persona open source?
TopGit's metadata for adonisjs/persona does not record a license. Most public repositories on GitHub ARE open source, but the exact terms vary — verify by opening the LICENSE file directly.
What is adonisjs/persona?
adonisjs/persona (adonisjs/persona) is a JavaScript project on GitHub. From the project's own README: Opinionated user management service for AdonisJs
Where do I read more about adonisjs/persona?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/adonisjs/persona is the definitive source.
Read full README in the tab above.
Still deciding about persona?
One click hands the question to an AI along with this page — see what it says about persona.