Skip to content

h3

INFO

Available in >4.3.0

This adapter converts between the h3 H3Event object and the OAuthRequest and OAuthResponse objects of this package. It works with each h3 framework, which includes Nuxt, Nitro, and an h3 application on its own.

You must install h3 yourself

This adapter calls h3 when it runs, but the other adapters do not call their framework. Thus you must install h3 (^1.15.0) in your project. The library declares it as an optional peer dependency.

Functions

ts
requestFromH3(event: H3Event): Promise<OAuthRequest>
ts
responseFromH3(event: H3Event): OAuthResponse
ts
handleH3Response(event: H3Event, oauthResponse: OAuthResponse): Promise<void>
ts
handleH3Error(e: unknown | OAuthException, event: H3Event): Promise<void>

Return or await handleH3Response and handleH3Error in your event handler. Then h3 waits until the library writes the response.

Example

ts
import { requestFromH3, handleH3Response, handleH3Error } from "@jmondi/oauth2-server/h3";

export default defineEventHandler(async (event) => {
  try {
    const oauthResponse = await authorizationServer.respondToAccessTokenRequest(
      await requestFromH3(event),
    );
    return handleH3Response(event, oauthResponse);
  } catch (e) {
    return handleH3Error(e, event);
  }
});