> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bawabah.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Astro

> Astro Example.

<Warning>
  This Example has not been tested yet. If you face any issues, please contact us at [contact@bawabah.app](mailto:contact@bawabah.app)
</Warning>

### Install Bawanah Library

First, we have to install Bawabah Library from NPM ([https://www.npmjs.com/package/bawabah](https://www.npmjs.com/package/bawabah)) using the command:

```
npm i bawabah
```

After installing the npm Package, we can start using it immediately:

<CodeGroup>
  ```typescript index.ts theme={"dark"}
  // Import Bawabah Library
  import Bawabah from 'bawabah';

  // Initialize Bawabah with your credentials
  const bw = new Bawabah();
  bw.init({
      appId: "your-app-id",
      appSecret: "your-app-secret"
  });
  ```
</CodeGroup>

> Replace `{your-app-id}` with your appId and `{your-app-secret}`with your appSecret From [Create Your First App](/getting-started/en/quickstart#create-your-first-app) Step.

### **Create Callback Route**

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:

<CodeGroup>
  ```typescript src/pages/login/callback.ts theme={"dark"}
  import type { APIRoute } from "astro";
  import Bawabah from "bawabah";

  // Initialize Bawabah
  const 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" } }
      );
    }
  };
  ```
</CodeGroup>

<Note>
  **Need help?**  Join our [<u>community</u>](https://discord.gg/9YpqwdNpxy).
</Note>

## Create Login Page

Create the Login Page at `src/pages/login.astro`:

<CodeGroup>
  ```html src/pages/login.astro theme={"dark"}
  ---


  ---

  <html lang="ar">
    <head>
      <meta charset="UTF-8" />
      <title>My Project</title>
      <style>
        body {
          display: flex;
          justify-content: center;
          align-items: center;
          min-height: 100svh;
        }
        h1 {
          width: 100%;
          text-align: center;
        }
      </style>
    </head>
    <body>
      <h1>Welcome to my Website</h1>
      <div id="login-form"></div>

      <!-- Load Bawabah login form -->
      <script src="https://bawabah.app/app/login-form.js"></script>
      <script>
        startBawabah({
          element: "login-form",
          appId: "your-app-id", // 🔑 replace with real appId
          callbackUrl: "http://localhost:4321/login/callback"
        })
      </script>
    </body>
  </html>
  ```
</CodeGroup>

<Note>
  **Need help?**  Join our [<u>community</u>](https://discord.gg/9YpqwdNpxy).
</Note>
