# Clerk Nuxt SDK

The Clerk Nuxt SDK gives you access to prebuilt components, composables, and helpers to make user authentication easier. Refer to the [quickstart guide](/content/docs/nuxt/getting-started/quickstart/index.html) to get started.

## [Integration](/content/docs/reference/nuxt/overview#integration/index.html)

To configure Clerk with Nuxt, you must pass the `@clerk/nuxt` module to your Nuxt config in your `nuxt.config.ts` file. See the [reference](/content/docs/reference/nuxt/integration/index.html) for more information on configuring the module, including setting Clerk options like `signInForceRedirectUrl`.

## [Client-side helpers](/content/docs/reference/nuxt/overview#client-side-helpers/index.html)

Because the Nuxt SDK is built on top of the Clerk Vue SDK, you can use the composables that the Vue SDK provides. These composables include access to the [Clerk](/content/docs/nuxt/reference/objects/clerk/index.html) object, [User object](/content/docs/nuxt/reference/objects/user/index.html), [Organization object](/content/docs/nuxt/reference/objects/organization/index.html), and a set of useful helper methods for signing in and signing up. Learn more in the [Clerk Vue SDK reference](/content/docs/reference/vue/overview/index.html).

- [useUser()](/content/docs/nuxt/reference/composables/use-user/index.html)
- [useClerk()](/content/docs/nuxt/reference/composables/use-clerk/index.html)
- [useAuth()](/content/docs/nuxt/reference/composables/use-auth/index.html)
- [useSignIn()](/content/docs/nuxt/reference/composables/use-sign-in/index.html)
- [useSignUp()](/content/docs/nuxt/reference/composables/use-sign-up/index.html)
- [useSession()](/content/docs/nuxt/reference/composables/use-session/index.html)
- [useSessionList()](/content/docs/nuxt/reference/composables/use-session-list/index.html)
- [useOrganization()](/content/docs/nuxt/reference/composables/use-organization/index.html)

## [Objects](/content/docs/reference/nuxt/overview#objects/index.html)

Learn about the [key Clerk objects](/content/docs/nuxt/reference/objects/overview/index.html) that power many of Clerk's SDKs.

## [Types](/content/docs/reference/nuxt/overview#types/index.html)

See the [reference docs on types](/content/docs/nuxt/reference/types/overview/index.html) to get more information about the different types available for typing your application.

## [`Auth` object](/content/docs/reference/nuxt/overview#auth-object/index.html)

The `Auth` object is available at `event.context.auth()` in your [event handlers⁠](https://h3.unjs.io/guide/event-handler). This JavaScript object contains important information like session data, your user's ID, as well as their Organization ID. Learn more about the [`Auth` object](/content/docs/reference/backend/types/auth-object/index.html).

### [`event.context.auth()` options](/content/docs/reference/nuxt/overview#event-context-auth-options/index.html)

- Name `opts?` Type `{acceptsToken: TokenType, treatPendingAsSignedOut: boolean }` Description

An object that can be used to configure the behavior of the `event.context.auth()` function. It accepts the following properties:

- `acceptsToken?`: The type of authentication token(s) to accept. Valid values are:
    - `'session_token'` - authenticates a user session.
    - `'oauth_token'` - authenticates a machine request using OAuth.
    - `'m2m_token'` - authenticates a machine to machine request.
    - `'api_key'` - authenticates a machine request using API keys.
    Can be set to:
    - A single token type.
    - An array of token types.
    - `'any'` to accept all available token types.
    Defaults to `'session_token'`.
  - `treatPendingAsSignedOut?`: A boolean that indicates whether to treat [pending session status](/content/docs/nuxt/reference/types/session-status#properties/index.html) as signed out. Defaults to `true`.

### [Example: Protect a route based on token type](/content/docs/reference/nuxt/overview#example-protect-a-route-based-on-token-type/index.html)

The following example uses `event.context.auth()` to protect the route based on token type:

```javascript
export default eventHandler((event) => {
  // Use `event.context.auth()` to protect a route based on token type
  const authObject = event.context.auth({ acceptsToken: 'any' })

if (authObject.tokenType === 'session_token') {
    console.log('This is a session token from a user')
  } else {
    console.log(`This is a ${authObject.tokenType} token`)
  }

return {}
})
```

## [`clerkMiddleware()`](/content/docs/reference/nuxt/overview#clerk-middleware/index.html)

The `clerkMiddleware()` helper integrates Clerk authentication and authorization into your Nuxt application through middleware. Learn more in the [clerkMiddleware() reference](/content/docs/reference/nuxt/clerk-middleware/index.html).

## [`clerkClient`](/content/docs/reference/nuxt/overview#clerk-client/index.html)

[`clerkClient`](/content/docs/reference/backend/overview/index.html) is a wrapper around the [Backend API⁠](/content/docs/reference/backend-api/index.html) that makes it easier to interact with the API. For example, to retrieve a list of all users in your application, you can use the `users.getUserList()` method instead of manually making a fetch request to the `https://api.clerk.com/v1/users` endpoint.

To access a resource, you must first instantiate a `clerkClient` instance. See the [reference documentation](/content/docs/reference/backend/overview/index.html) for more information.

Learn more about [reading user data](/content/docs/nuxt/guides/users/reading/index.html).

## [Protect pages and API routes](/content/docs/reference/nuxt/overview#protect-pages-and-api-routes/index.html)

To protect pages, use the `useAuth()` helper to protect a single page, or use Nuxt's built-in [route middleware⁠](https://nuxt.com/docs/4.x/guide/directory-structure/middleware) to protect multiple pages. Learn more about [protecting content](/content/docs/nuxt/guides/secure/protect-content/index.html).

To protect API routes (`/api/**`), use the `clerkMiddleware()` helper. Learn more in the [clerkMiddleware() reference](/content/docs/reference/nuxt/clerk-middleware/index.html).
