# Common Frontend Flows

#### Gated Page Load

1. Read `ready` and `authenticated` from `usePrivy()`.
2. If `ready` is `false`, render a loading state.
3. If `ready` is `true` but `authenticated` is `false`, render a connect prompt that calls `login`.
4. Once `authenticated` is `true`, read `user.wallet.address` and fetch any user-specific data from your backend using the identity token.

#### Authenticated API Request

1. Obtain `identityToken` from `useIdentityToken()`.
2. Attach it as `Authorization: Bearer <identityToken>` on every request to your backend.
3. On the server, pass the header to `verifyPrivyWallet` to extract the user.
4. Use the returned `user.wallet.address` to look up balances, vault positions, or any City-powered feature.

#### Connecting a Wallet to Vault Operations

Once the wallet is verified, combine both SDK clients for a full-stack flow:

```
// Client-side: create a CityClient with the user's wallet
import { CityClient } from "@cityprotocol/core";

const cityClient = new CityClient(walletClient);

// Now the same wallet that Privy authenticated can call vault methods
const hash = await cityClient.deposit({
  vault: "0xVaultAddress",
  assets: 1000000n,
});
```

The `walletClient` here is a Viem wallet client backed by the same account Privy manages. This ensures the on-chain signer and the backend-verified identity always correspond to the same address.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://city-protocol.gitbook.io/docs/software-development-kit/wallet/common-frontend-flows.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
