A fullstack SDK combines the frontend-only SDK and backend-only SDKNext.js Icon into one. A fullstack SDK is necessary for frameworks that support multiple rendering strategies (SSR, SSG, etc.), middleware, data fetching, and more. Examples of such frameworks would be Next.js or Rails.
Inside your Clerk middleware, add checks for the headers on the requestState. Apply these headers to the Response and handle any existing location headers (e.g. redirects).
clerk-middleware.ts
import { clerkClient as defaultClerkClient } from'./client.ts'constclerkMiddleware= (options) => {returnasync (context, next) => {constclerkClient=options.clerkClient || defaultClerkClientconstrequestState=awaitclerkClient.authenticateRequest(context.req, { authorizedParties: ['https://example.com'], })if (requestState.headers) {// This adds observability headers to the resrequestState.headers.forEach((value, key) =>context.res.headers.append(key, value))constlocationHeader=requestState.headers.get('location')if (locationHeader) {returncontext.redirect(locationHeader,307) } elseif (requestState.status ==='handshake') {thrownewError('Clerk: unexpected handshake without redirect') } }context.set('clerkAuth',requestState.toAuth())context.set('clerk', clerkClient)awaitnext() }}