Files
Rishabh PoddarandGitHub 7d4888d961 Updates with-supertokens example app (#60901)
Refactors with-supertokens example app to move some of the helper
functions into the SDK.
2024-01-20 00:35:28 +00:00

24 lines
773 B
TypeScript

import { ensureSuperTokensInit } from "@/app/config/backend";
import { NextResponse, NextRequest } from "next/server";
import { withSession } from "supertokens-node/nextjs";
ensureSuperTokensInit();
export function GET(request: NextRequest) {
return withSession(request, async (err, session) => {
if (err) {
return NextResponse.json(err, { status: 500 });
}
if (!session) {
return new NextResponse("Authentication required", { status: 401 });
}
return NextResponse.json({
note: "Fetch any data from your application for authenticated user after using verifySession middleware",
userId: session.getUserId(),
sessionHandle: session.getHandle(),
accessTokenPayload: session.getAccessTokenPayload(),
});
});
}