Skip to content

Authentication

Mkdirs uses Auth.js v5 for authentication, supports email/password, GitHub, and Google authentication.

Configuration

  1. Generate the AUTH_SECRET variable

    AUTH_SECRET is a random value, and you can generate one via running:

    Terminal window
    npx auth secret
    # or
    openssl rand -base64 32

    Then set it to the .env file.

    .env
    # [required]
    AUTH_SECRET=secret
  2. [Optional] Get the GitHub client variables

    If you want to use GitHub as an OAuth provider, you need to update the AUTH_GITHUB_ID and AUTH_GITHUB_SECRET variables.

    Follow the steps here to get the client_id and client_secret from the GitHub Developer Settings.

    For the callback URL, it is https://your-domain.com/api/auth/callback/github or http://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_id
    AUTH_GITHUB_SECRET = your_secret_client

    GitHub Client

  3. [Optional] Get the Google client variables

    If you want to use Google as an OAuth provider, you need to update the AUTH_GOOGLE_ID and AUTH_GOOGLE_SECRET variables.

    You can get the client_id and client_secret from the Google Cloud Console.

    For the callback URL, it is https://your-domain.com/api/auth/callback/google or http://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.com
    AUTH_GOOGLE_SECRET = your_secret_client

    Google Client

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.

Further Reading