> ## 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.

# Cloudflare

> Cloudflare 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**

Create a Cloudflare worker to capture the user session on the callback route.

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

  const bw = new Bawabah();
  bw.init({
    appId: "your-app-id",
    appSecret: "your-app-secret",
  });

  export default {
    async fetch(request: Request): Promise<Response> {
      const url = new URL(request.url);

      if (url.pathname === "/login/callback") {
        const sessionId = url.searchParams.get("sessionId");
        if (!sessionId) {
          return new Response("Missing sessionId", { status: 400 });
        }

        try {
          const result = await bw.capture(sessionId);

          // --- Perform your login/signup logic here ---

          return Response.json({ loggedIn: true });
        } catch (err: any) {
          return Response.json(
            { error: "Failed to capture session", details: String(err) },
            { status: 500 }
          );
        }
      }

      return new Response("Not Found", { status: 404 });
    },
  };
  ```
</CodeGroup>

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

## Create Login Page

You can create the login page with any framework or with just plain HTML, like this example:

<CodeGroup>
  ```tsx login.html theme={"dark"}
  <!DOCTYPE html>
  <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>

    <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:8787/login/callback"
      })
    </script>
  </body>
  </html>
  ```
</CodeGroup>

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