mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Refactors with-supertokens example app to move some of the helper functions into the SDK.
24 lines
773 B
TypeScript
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(),
|
|
});
|
|
});
|
|
}
|