The AUTH0_DOMAIN, AUTH0_CLIENT_ID, and AUTH0_CLIENT_SECRET can be obtained from the Auth0 Dashboard once you've created an application. This application must be a Regular Web Application.
The SESSION_SECRET is the key used to encrypt the session cookie. You can generate a secret using openssl:
openssl rand -hex 64
The APP_BASE_URL is the URL that your application is running on. When developing locally, this is most commonly http://localhost:3000.
[!IMPORTANT]
You will need to register the following URLs in your Auth0 Application via the Auth0 Dashboard:
Add http://localhost:3000/auth/callback to the list of Allowed Callback URLs
Add http://localhost:3000 to the list of Allowed Logout URLs
Routes
The SDK for Fastify Web Applications mounts 4 main routes:
/auth/login: the login route that the user will be redirected to to initiate an authentication transaction. Supports adding a returnTo querystring parameter to return to a specific URL after login.
/auth/logout: the logout route that must be added to your Auth0 application's Allowed Logout URLs
/auth/callback: the callback route that must be added to your Auth0 application's Allowed Callback URLs
/auth/backchannel-logout: the route that will receive a logout_token when a configured Back-Channel Logout initiator occurs
To disable this behavior, you can set the mountRoutes option to false (it's true by default):
fastify.register(auth0, {
mountRoutes: false
});
Additionally, by setting mountConnectRoutes to true (it's false by default) the SDK also can also mount 4 routes useful for account-linking:
/auth/connect: the route that the user will be redirected to to initiate account linking
/auth/connect/callback: the callback route for account linking that must be added to your Auth0 application's Allowed Callback URLs
/auth/unconnect: the route that the user will be redirected to to initiate account linking
/auth/unconnect/callback: the callback route for account linking that must be added to your Auth0 application's Allowed Callback URLs
[!IMPORTANT]
When mountRoutes is set to false, setting mountConnectRoutes has no effect.
3. Adding Login and Logout
When using the built-in mounted routes, the user can be redirected to /auth/login to initiate the login flow and /auth/logout to log out.
[!IMPORTANT]
The above is to protect server-side rendering routes by the means of a session, and not API routes using a bearer token.
Requesting an Access Token to call an API
If you need to call an API on behalf of the user, you want to specify the audience parameter when registering the plugin. This will make the SDK request an access token for the specified audience when the user logs in.
Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
What is Auth0?
Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?
This project is licensed under the MIT license. See the LICENSE file for more info.
Auth0 Authentication SDK for Fastify Applications on JavaScript runtimes
We found that @auth0/auth0-fastify demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 17 open source maintainers collaborating on the project.
Package last updated on 09 Apr 2026
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
GitHub account BufferZoneCorp published sleeper packages that later added credential theft, GitHub Actions tampering, fake go wrappers, and SSH persistence.