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 Astro to create the route, then capture the user session with the capture() function:
import type { APIRoute } from "astro";import Bawabah from "bawabah";// Initialize Bawabahconst bw = new Bawabah();bw.init({ appId: "your-app-id", appSecret: "your-app-secret",});export const GET: APIRoute = async ({ url }) => { const sessionId = url.searchParams.get("sessionId"); if (!sessionId) { return new Response("Missing sessionId in query", { status: 400 }); } try { const result = await bw.capture(sessionId); // --- Perform your login/signup logic here --- return new Response( JSON.stringify({ loggedIn: true }), { status: 200, headers: { "Content-Type": "application/json" } } ); } catch (err: any) { return new Response( JSON.stringify({ error: "Failed to capture session", details: err.message || String(err), }), { status: 500, headers: { "Content-Type": "application/json" } } ); }};