# Guest Users

Guest accounts allow users to immediately start using your application without going through a full registration process. This feature is particularly useful for applications where you want to reduce friction in the user onboarding process.

## Key features

* Locally persisted, so guest users can leave and return to the same account on the same device
* Fully functional embedded wallets
* Upgradeable to full accounts with email, social login, or phone
* Can be logged out and deleted as needed

## Create a guest account

Use the `signUpGuest` method to create a guest account. This returns an `AuthResponse` with `isAnonymous: true` in the user object:

:::code-group

```tsx [auth.tsx]
import openfort from "./openfortConfig";

async function handleGuest() {
  const result = await openfort.auth.signUpGuest();

  console.log('Guest user created:', result.user.id);
  console.log('Is anonymous:', result.user.isAnonymous);
}
```

```ts [openfortConfig.ts]
import { Openfort } from '@openfort/openfort-js';

const openfort = new Openfort({
  baseConfiguration: {
    publishableKey: "YOUR_OPENFORT_PUBLISHABLE_KEY",
  }
});

export default openfort;
```

```json [response.json]
{
  "token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "id": "usr_cc9ed2b7-c5f5-4c43-8dca-c4b104ba1762",
    "isAnonymous": true,
    "createdAt": "2024-03-20T12:00:00Z",
    "updatedAt": "2024-03-20T12:00:00Z"
  }
}
```

:::

## Upgrade a guest account

Convert a guest user to a full account by adding an email address. Use `addEmail` to send a verification email:

:::code-group

```tsx [auth.tsx]
import openfort from "./openfortConfig";

async function upgradeGuestWithEmail(email: string) {
  const result = await openfort.auth.addEmail({
    email: email,
    callbackURL: 'https://your-app.com/verify-email',
  });

  console.log('Verification email sent');
}
```

```json [response.json]
{
  "status": "pending"
}
```

:::

After the user verifies their email, they can log in with email and password. The guest account is upgraded to a full account.

You can also upgrade guest accounts using:

* [OAuth linking](/docs/products/embedded-wallet/javascript/auth/user-management/linking#link-social-accounts)
* [Phone number linking](/docs/products/embedded-wallet/javascript/auth/user-management/linking#link-phone-number)

## Example implementation

Here's a complete example of a guest authentication flow:

:::code-group

```jsx [GuestAuth.jsx]
import openfort from "./openfortConfig";
import { useState } from "react";
import { useRouter } from "next/navigation";

function GuestAuth() {
  const router = useRouter();
  const [status, setStatus] = useState(null);

  const handleGuest = async () => {
    setStatus({ type: "loading", title: "Creating guest account..." });

    try {
      const result = await openfort.auth.signUpGuest();

      setStatus({ type: "success", title: "Guest account created" });
      console.log('Guest user ID:', result.user.id);

      router.push("/");
    } catch (error) {
      setStatus({ type: "error", title: "Error creating guest account" });
    }
  };

  return (
    <div>
      <button onClick={handleGuest} disabled={status?.type === "loading"}>
        {status?.type === "loading" ? "Creating..." : "Continue as Guest"}
      </button>
    </div>
  );
}
```

```jsx [LoginOptions.jsx]
function LoginOptions({ onGuest, onLogin }) {
  return (
    <div className="space-y-4">
      <button onClick={onGuest}>
        Continue as Guest
      </button>
      <button onClick={onLogin}>
        Login or Create Account
      </button>
    </div>
  );
}
```

:::
