Introduction
Payload CMS auth plugin is created and maintained by Sourab Pramanik. This plugin extends the Payload authentication process and implements OAuth and Passkey based authentication features. In its core it uses Payload's auth conventions to adhere to its standards.
NOTE: It works with all Payload versions >= 3.0
1. How it works?
The initial goal in developing this plugin was to abstract its configurations and the resources it utilizes, minimizing the setup required by developers. This way, integrating any supported provider with Payload CMS involves minimal effort.
TODO: There is a scope for future improvements to make every implementation more and more flexible and straightforward
1.1. Collections
The plugin creates an Accounts collection with the slug accounts
(or you can use a different slug), which includes all the necessary fields it needs to store the provider specific user records. This collection establishes a one-to-one relationship with the Users collection, allowing existing users to sign in with multiple providers. The Accounts collection stores information such as the provider's name, issuer, etc., and creates a relation between the account to the user upon first sign-in.
A single user can have multiple accounts, but each account can be associated with only one user.
If you already have a collection with the slug accounts
, it can cause a conflict and prevent the plugin from integrating successfully. To avoid this issue, make sure to use a different slug.
1.2. Endpoints
Payload 3.0 is built on top of NextJS framework, and there are two sides to this application. One is admin
and another is frontend
. This plugin right now enables authentication for the admin
side but soon it will also support authentication for the frontend
side.
For every provider with different protocols, the endpoints are already configured in the plugin. It creates catchl-all segement route and process all requests and responses that directly invokes the plugin core and handles the authentication.
1.3. Session
Payload has exposed ways to use their inbuilt session mechanism to tweak it the way you need. It is helpful to understand and tailor the user session and extend it if needed. To keep things simple and even, the core of the plugin uses Payload session.