After installing the npm Package, we can start using it immediately:
// Import Bawabah Libraryimport Bawabah from 'bawabah';// Initialize Bawabah with your credentialsconst bw = new Bawabah();bw.init({ appId: "your-app-id", appSecret: "your-app-secret"});
Replace {your-app-id} with your appId and {your-app-secret}with your appSecret From Create Your First App Step.
Now we will create the callback route to capture the user session. In this example, we will use Next.js to create the route, then capture the user session with the capture() function:But before that, we need to install the necessary packages using this command:
npm i next react react-dom
// File: app/login/callback/route.tsimport { NextRequest } from 'next/server';import Bawabah from 'bawabah';// Initialize Bawabah with your credentialsconst bw = new Bawabah();bw.init({ appId: "your-app-id", appSecret: "your-app-secret"});// Callback route for Bawabah redirectexport async function GET(req: NextRequest) { const { searchParams } = new URL(req.url); const sessionId = searchParams.get("sessionId"); // /login/callback?sessionId=abc123 if (!sessionId) { return new Response("Missing sessionId in query", { status: 400 }); } try { // Capture user session from Bawabah const result = await bw.capture(sessionId); // --- Perform Your User Login/Signup Logic here --- return Response.json({ loggedIn: true }, { status: 200 }); } catch (err) { return Response.json( { error: "Failed to capture session", details: String(err) }, { status: 500 } ); }}