3. Adding auth APIs
Add authentication APIs to your backend using SuperTokens for sign in and sign up functionality.
We will add all the backend APIs for auth on /api/auth. This can be changed by setting the apiBasePath property in the appInfo object in the appInfo.ts file. For the rest of this page, we will assume you are using /api/auth.
1. Create the app/api/auth/[[...path]]/route.ts route
- Be sure to create the
auth/[[...path]]folder in theapp/api/folder. route.tsuses thegetAppDirRequestHandlerhelper fromsupertokens-nodeto handle authentication APIs such as sign-up and sign-in. The full folder path should be/app/api/auth/[[...path]]/route.ts.- An example of this can be found here.
2. Expose the SuperTokens APIs
import { getAppDirRequestHandler } from "supertokens-node/nextjs";
import type { NextRequest } from "next/server";
import { ensureSuperTokensInit } from "../../../config/backend";
ensureSuperTokensInit();
const handleCall = getAppDirRequestHandler();
export async function GET(request: NextRequest) {
return handleCall(request);
}
export async function POST(request: NextRequest) {
return handleCall(request);
}
export async function DELETE(request: NextRequest) {
return handleCall(request);
}
export async function PUT(request: NextRequest) {
return handleCall(request);
}
export async function PATCH(request: NextRequest) {
return handleCall(request);
}
export async function HEAD(request: NextRequest) {
return handleCall(request);
}
3. Use the login widget
If you are now able to sign in or sign up, this means the backend setup is done correctly! If not, please feel free to ask questions on Discord