Default (Auth.js) Auth Provider
The default (Auth.js) auth provider uses Auth.js and a user collection to authenticate and authorize users to your TinaCMS instance.
Getting Started
If you have not set up self-hosting yet, we recommend using the
init backendcommand. See the Getting started doc for more information.
To get started you will need to install the following dependencies:
Make sure you have a database adapter setup before continuing.
Update Your TinaCMS Config
We need to add the Auth Provider and a user collection to the tina/config.{ts,js} file.
The TinaUserCollection is a special collection that is used to store user information. This collection will be seeded from thecontent/users/index.json file, but the file will not be updated when the users collection is updated. This prevents sensitive information such as passwords from being written to the Git repository.
Add Seed Data
Create a file called content/users/index.json that contains the initial seed user:
After logging in, you can update the username and password
Update TinaCMS Backend
Update your /api/tina/[...routes].{ts,js} file to use the Auth.js backend.
Testing
Now that you have set up the Auth.js auth provider you can test it out.
Testing Authentication Locally
Add the following to your script to your package.json file.
This will allow you to test the authentication flow locally.
Now you can open your browser and navigate to http://localhost:3000/admin/index.html and you should be redirected to the login page.
Updating Your Password
Once you have logged in, you will be prompted to update your password. This should be done so that the password is not stored in plain text in your repository.
Managing users
To add additional users, navigate to the Users collection in the sidebar to add or edit users. See User Management for more details.
Configuring other Auth.js Login Providers
Auth.js supports many different login providers. When self-hosting, it is possible to use any of these providers with some configuration changes. The user collection will still be used for authorization, but the login flow will be handled by the login provider.
As an example, we can configure the Discord OAuth login provider.