UNPKG

@cipherstash/nextjs

Version:

Nextjs package for use with @cipherstash/protect

37 lines (36 loc) 989 B
import { CS_COOKIE_NAME, logger, resetCtsToken, setCtsToken } from "../chunk-GVV2ST3S.js"; // src/clerk/index.ts import { NextResponse } from "next/server"; var protectClerkMiddleware = async (auth, req) => { const { userId, getToken } = await auth(); const ctsSession = req.cookies.has(CS_COOKIE_NAME); if (userId && !ctsSession) { const oidcToken = await getToken(); if (!oidcToken) { logger.debug( "No Clerk token found in the request, so the CipherStash session was not set." ); return NextResponse.next(); } return await setCtsToken(oidcToken); } if (!userId && ctsSession) { logger.debug( "No Clerk token found in the request, so the CipherStash session was reset." ); return resetCtsToken(); } logger.debug( "No Clerk token found in the request, so the CipherStash session was not set." ); return NextResponse.next(); }; export { protectClerkMiddleware }; //# sourceMappingURL=index.js.map