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:Then set it to the
.env
file. -
[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. -
[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.
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.
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.