Authentication
Mkdirs uses Auth.js v5 for authentication, supports email/password, GitHub, and Google authentication.
Configuration
-
Generate the
AUTH_SECRET
variableAUTH_SECRET
is a random value, and you can generate one via running:Terminal window npx auth secret# oropenssl rand -base64 32Then set it to the
.env
file..env # [required]AUTH_SECRET=secret -
[Optional] Get the GitHub client variables
If you want to use GitHub as an OAuth provider, you need to update the
AUTH_GITHUB_ID
andAUTH_GITHUB_SECRET
variables.Follow the steps here to get the
client_id
andclient_secret
from the GitHub Developer Settings.For the callback URL, it is
https://your-domain.com/api/auth/callback/github
orhttp://localhost:3000/api/auth/callback/github
for local development..env # [only required if you want to support GitHub authentication]AUTH_GITHUB_ID = your_secret_client_idAUTH_GITHUB_SECRET = your_secret_client -
[Optional] Get the Google client variables
If you want to use Google as an OAuth provider, you need to update the
AUTH_GOOGLE_ID
andAUTH_GOOGLE_SECRET
variables.You can get the
client_id
andclient_secret
from the Google Cloud Console.For the callback URL, it is
https://your-domain.com/api/auth/callback/google
orhttp://localhost:3000/api/auth/callback/google
for local development..env # [only required if you want to support Google authentication]AUTH_GOOGLE_ID = your_secret_client_id.apps.googleusercontent.comAUTH_GOOGLE_SECRET = your_secret_client
Special Note
-
Please note that the environment variables are different in development and production environments, make sure to create two different OAuth applications for the production and development environments.
-
If you still have trouble with the authentication, for example,
redirect_uri_mismatch
or other issues, you can try to add the following environment variables to the.env
file, only in the production environment..env AUTH_TRUST_HOST=trueAUTH_URL=https://your-domain.com/api/auth
Video tutorial
If you are interested in Next Auth V5, you can refer to the following video tutorial, it is a more advanced guide for Next Auth V5, so much better than the official documentation.