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

# Sign testing JWT

> Generate a signed JWT for testing external auth — development only

## Overview

Returns a function that calls the Sublay API to sign a JWT using your project's private key. This is intended **exclusively for development and testing** of external authentication flows — it lets you generate valid user JWTs from the client without setting up a backend.

> [!WARNING]
>
> **Never use this hook in production.** Calling this function exposes your project's private key in client-side code, which is a critical security vulnerability. In production, JWT signing must happen on your backend server. See the [External Authentication](https://docs.sublay.io/v7/sdk/authentication/external.md) guide.

## Usage Example

```tsx theme={null}
import { useSignTestingJwt } from "@sublay/react-js";
import { useAuth } from "@sublay/react-js";

function DevAuthHelper() {
  const signTestingJwt = useSignTestingJwt();
  const { signInWithToken } = useAuth();

  const signInAsTestUser = async () => {
    const token = await signTestingJwt({
      projectId: "your-project-id",
      privateKey: "your-private-key", // ⚠️ Development only
      userData: {
        id: "external-user-123",
        name: "Test User",
        email: "test@example.com",
      },
    });

    if (token) {
      await signInWithToken(token);
    }
  };

  return <button onClick={signInAsTestUser}>Sign in as test user</button>;
}
```

## Parameters

**projectId** `string` *required*

Your Sublay project ID.

**privateKey** `string` *required*

Your project's private key, used to sign the JWT. This key is available in your Sublay dashboard. **Never expose this in production code.**

**userData** `object` *required*

The user data to encode in the JWT payload. Must include `id` (the external user's identifier). Additional fields are passed through as custom claims.

```ts theme={null}
{
  id: string;           // Required: external user identifier
  [key: string]: any;   // Optional: name, email, avatar, etc.
}
```

## Returns

Returns `Promise<string | undefined>`. On success, resolves to a signed JWT string that can be passed to the external auth sign-in flow.

## Notes

* The function logs a console warning each time it is called as a reminder that it is not for production use.
* Use the returned token with the external authentication flow described in [External Authentication](https://docs.sublay.io/v7/sdk/authentication/external.md).


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