Email and password management
14 files0 packages1 dependency
This pack adds an account settings area where signed-in users manage their own account. They update their name and email on a profile page and change their password on a security page.
- A pending email change can be resent or cancelled from the profile page, and the account keeps signing in with its confirmed address until then.
- A branded, MJML change-email message that names both the old and the new address.
- A new email and a new password meet the same rules as signup. The security page shows a strength bar and a checklist of the password rules.
Depends on Auth
This pack extends the auth pack's User model and reuses its email-verification flow. Apply the auth pack first.
Apply the email & password management pack with Flow. Start a new session in your selected coding agent and execute the following slash command inside it.
$ npx @adonisplus/flow apply --pack=email-password-management --agent=claude
$ npx @adonisplus/flow apply --pack=email-password-management --agent=codex
$ npx @adonisplus/flow apply --pack=email-password-management --agent=cursor
$ npx @adonisplus/flow apply --pack=email-password-management --agent=opencode
After applying, Flow will make the following changes to your app.
- Reuse your account settings area to host the profile and security pages, or establish one when you have none.
- Land the backend as shipped, from the profile, security, and account-password controllers through the validators, the change-email mailer and template, the resend branch, and the routes.
- Restyle the profile and security screens to your design system.
- Run the tests, then walk the profile update, email change, and password change and show you the result.
Delta will differ
Flow adapts the pack to your app, so the exact set of created and edited files depends on what you already have. This is the shape of an apply onto the React starter kit with the auth pack in place.
Layouts
settings.tsxinertia/layouts/settings.tsxLists the Profile and Security pages in the settings sidebar.editedapp.tsxinertia/layouts/app.tsxLinks the settings area in the navigation.edited
Validators
user.tsapp/validators/user.tsAdds the update-profile and change-password validators.edited
Controllers & responses
profile_controller.tsapp/controllers/profile_controller.tsRenders the profile page and applies name and email changes.createdsecurity_controller.tsapp/controllers/security_controller.tsRenders the security page that hosts the change-password form, and passes it the password policy.createdaccount_password_controller.tsapp/controllers/account_password_controller.tsVerifies the current password before setting the new one.createdemail_verifications_controller.tsapp/controllers/email_verifications_controller.tsBranches the resend so an active account gets the change email.edited
Mailers & email templates
email_change_provision.tsapp/mails/email_change_provision.tsThe change-email message, carrying the verification link.createdchange_email.edgeresources/views/emails/change_email.edgeBody of the change-email message, naming the old and new address.created
Pages
profile.tsxinertia/pages/account/profile.tsxProfile screen with the name and email form and the pending-email card.createdsecurity.tsxinertia/pages/account/security.tsxSecurity screen with the change-password form and the password strength meter.created
Routes
routes.tsstart/routes.tsAdds the profile, security, and password routes to your authenticated group.edited
Tests
profile_management.spec.tstests/browser/auth/profile_management.spec.tsProfile update, email change, revert, resend, and cancel specs.createdchange_password.spec.tstests/browser/auth/change_password.spec.tsChange-password specs.created
Configuration
Section titled "Configuration"The change-email link is backed by the withManagedEmail() mixin on the User model, the same mixin auth composes. It mints each verification token and stores it in a database table. Pass an options object to the mixin to change its defaults.
expiresInstring | number1 day.tablestringemail_verification_tokens.tokenSecretLengthnumber40.export default class User extends compose(
UserSchema,
withAuthFinder(hash),
withManagedEmail({ expiresIn: '2 hours' })
) {}Changing an email keeps the old one active
Section titled "Changing an email keeps the old one active"An account carries two addresses. email is the confirmed one that signs the user in, and unverifiedEmail holds a change still waiting on confirmation. Submitting a new email writes it to unverifiedEmail and sends the change-email message there, while the confirmed address goes on working for login until the new one is confirmed.
Submitting the current confirmed email while a change is pending reverts it. The pending address is cleared and no mail is sent, which is what cancelling a pending change relies on. Because the uniqueness check ignores the user's own row, resubmitting an unchanged email is never a duplicate. A new email meets the same rules as signup. When signup rejects disposable email addresses, an email change rejects them too.
A pending change can also be resent, throttled to one message a minute. Inside that window the request does nothing and answers as it would have, so the timing stays invisible.
A password change needs the current password
Section titled "A password change needs the current password"The change verifies the current password with a constant-time comparison before setting the new one. A wrong current password is rejected and nothing changes. Assigning the new password re-hashes it on save, so only the hash is ever stored.
The new password meets the same rules as signup: the password policy, and the leaked-password check when signup uses it. The security page shows a strength bar and a checklist of the policy requirements for the new password.
Added in Flow 0.2.0.