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

# Auth

> Cashback Hive SDK auth API reference: check sign-in state and sign members in or out with auth.isSignedIn(), auth.signIn() and auth.signOut().

See [Members and authentication](https://developer.cashbackhive.com/guides/members-and-auth.md) for the full flow, including popup fallback and token storage.

## `auth.isSignedIn()`

```ts theme={null}
auth.isSignedIn(): boolean
```

**Returns** `true` if a member token is stored. This is a cheap synchronous check and doesn't validate the token with the API; a stale token will still return `true` until the SDK discovers it's invalid (on load, or on the next member request) and signs the member out.

## `auth.signIn()`

Open the Cashback Hive sign-in window and resolve with the member once they've signed in.

```ts theme={null}
auth.signIn(): Promise<Member>
```

**Behaviour**

1. Opens a 480×640 popup to the sign-in page, passing your key, the current origin and the current URL.
2. Waits for the sign-in page to post a `cbh:auth` message back (origin-checked), or for a token to appear in `localStorage` from another tab.
3. Stores the token, fetches the member profile, emits [`auth:change`](https://developer.cashbackhive.com/reference/events#auth-change), and resolves with the [`Member`](https://developer.cashbackhive.com/reference/types#member).

If the popup is blocked, the current page is redirected to the sign-in page instead and the promise never settles (the page unloads). The member is brought back afterwards and signed in on that load.

In [mock mode](https://developer.cashbackhive.com/guides/local-development.md#option-2-mock-mode), resolves after \~300 ms with a sample member; no popup is opened.

**Rejects** with an `Error` whose message is:

| Message | Meaning |
| - | - |
| `Sign-in window was closed` | The member closed the popup before finishing. Treat as a cancel. |
| `Sign-in failed` or a specific message | The sign-in page reported an error. |

> [!WARNING]
>
> Call `signIn()` directly from a user gesture such as a click handler. Browsers block `window.open` that isn't triggered synchronously by user input.

```ts theme={null}
button.addEventListener("click", async () => {
  try {
    const member = await sdk.auth.signIn();
    console.log("Welcome,", member.displayName);
  } catch (err) {
    if (err.message !== "Sign-in window was closed") {
      console.error(err);
    }
  }
});
```

## `auth.signOut()`

```ts theme={null}
auth.signOut(): void
```

Removes the stored token, clears the cached member, and emits [`auth:change`](https://developer.cashbackhive.com/reference/events#auth-change) with `member: null`. Synchronous; makes no network request.

```ts theme={null}
sdk.auth.signOut();
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.