Skip to main content

Nuxt Module

Integrate Unkey API key authentication into your Nuxt application with the official Nuxt module. Protect server routes and API endpoints.
1 min read

If you are using Nuxt, you can benefit from an almost zero-config experience with the @unkey/nuxt module.

Install#

Configuration#

@unkey/nuxt just requires your root key. Create an .env file in your project and add the following:

This can also be configured at runtime by setting the NUXT_UNKEY_TOKEN environment variable.

From this point onward, @unkey/nuxt will automatically:

  1. verify any API requests with an Authorization: Bearer xxx header.
  2. register a useUnkey() helper that allows access to an automatically configured unkey instance.

Usage#

Automatic verification#

You can access the automatically-verified unkey context on the server with event.context.unkey in your server routes or useRequestEvent().context.unkey in the Vue part of your app.

For example:

Unkey helper#

For more about how to use the configured helper provided by useUnkey(), you can see the API docs for the TypeScript client.

For example:

Disable telemetry#

By default, Unkey collects anonymous telemetry data to help us understand how our SDKs are used.

If you wish to disable this, you can do so by passing a boolean flag to the constructor: