Skip to content

Commit

Permalink
fix: add middleware and api routes usage for nuxt (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangsijie authored Dec 27, 2024
1 parent 36e55f1 commit 5939c87
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/quick-starts/framework/nuxt/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ import ApiResources from './api-resources/_index.mdx';

<ApiResources />

## Use in middleware or API routes \{#use-in-middleware-or-api-routes}

The composable `useLogtoClient()` and `useLogtoUser()` are not available in middleware or API routes. You can use the `logtoEventHandler()` function to get the Logto client and other context:

```ts title="api/auth/get-access-token.ts"
import { logtoEventHandler } from '@logto/nuxt';

export default defineEventHandler(async (event) => {
const config = useRuntimeConfig(event);
await logtoEventHandler(event, config);
const accessToken = await event.context.logtoClient.getAccessToken();
return { accessToken };
});
```

## Further readings \{#further-readings}

<FurtherReadings />

0 comments on commit 5939c87

Please sign in to comment.