Skip to content

erickweil/erickweil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

Better Auth Credentials Plugin

npm version

Generic credentials authentication plugin for Better Auth

The plugin itself can be used to authenticate to anything, as are you that handle the logic that verify user input credentials in the callback, and just need to return user data that will be used to create/update the user in the database.

(Early version, experimental, the behaviour WILL CHANGE)

Features

  • Full control over the authentication process
  • Auto sign-up (optional) and management of Account linking and session creation
  • Similar in behaviour to the default email & password flow, but YOU handle the verification of the credentials and allow automatically sign-up
  • Route customization, you can choose the route path and the body parameters (using zod schema that doubles as validation and OpenAPI documentation)
  • Supports custom callbacks for sign-in and sign-up events

Examples (All are built using express + MongoDB):

  • examples/basic - Basic usage example with a fake user store, showcasing the credentials callback functionality and how to handle user data
  • examples/ldap-auth - Uses this plugin to perform LDAP authentication, showing how easy is to use it

Considerations:

  • You need to return a email field after the authentication, this is used to create/update the user in the database, and also to link the account with the session (email field should be unique).
  • It's not intended to use this to re-implement password login, but to be used when you need to integrate with an external system that uses credentials for authentication, like LDAP, or any other system that you can verify the credentials and get user data. If you try to mimic password login by hashing and storing the password, aditional database round-trips will be needed as this plugin will search the user again after you alread did (just use the email & password flow or username plugin don't do this).

Installation https://www.npmjs.com/package/better-auth-credentials-plugin

npm install better-auth-credentials-plugin

About

Profile Readme

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published