> For the complete documentation index, see [llms.txt](https://docs.lingoql.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lingoql.com/sub0/apis-abi/practical-examples/wallet-backend-auth-and-accounts.md).

# Wallet backend: Auth and accounts

Use this page to ship the first user-facing endpoints.

### Best for

Email and password auth with a protected account area.

### What it shows

* Token issuance on signup and signin
* Protected reads with extracted claims
* Safe profile updates

### Use this when

You want the shortest path from user table to working account APIs.

### Pattern 1. Sign up and return a token

This is the safest starting point.

```json
{
  "id": "wallet-sign-up-01",
  "resource": "sign-up",
  "tokenize": {
    "custom_claim_fields": ["id", "email"],
    "type": "JWT",
    "algorithm": "HS256",
    "expiration": 3600,
    "encryption_key": "$ENV.JWT_SECRET_KEY",
    "property_name": "token"
  },
  "actionables": [
    {
      "id": 1,
      "mode": "QUERY",
      "payload_validation": [
        {
          "field": {
            "name": {
              "type": "STRING"
            }
          },
          "min_length": 2,
          "max_length": 255
        },
        {
          "field": {
            "email": {
              "type": "EMAIL"
            }
          },
          "max_length": 255
        },
        {
          "field": {
            "password": {
              "type": "STRING"
            }
          },
          "min_length": 8,
          "max_length": 255
        }
      ],
      "hashables": [
        {
          "property": "password",
          "algorithm": "BCRYPT",
          "options": {
            "rounds_cost": 12,
            "salt": "$ENV.MY_HASHING_SALT"
          }
        }
      ],
      "sql_query": {
        "query": "INSERT INTO users (id, name, email, password, wallet_balance, created_at, updated_at) VALUES ($1, $2, $3, $4, $5::float8, $6::timestamptz, $7::timestamptz) RETURNING id, name, email",
        "parameters": [
          "$GENERATOR.KSUID",
          "name",
          "email",
          "password",
          "0",
          "$DATETIME",
          "$DATETIME"
        ],
        "unique": ["email"]
      },
      "returnables": ["id", "name", "email"]
    }
  ]
}
```

### Pattern 2. Sign in and verify the stored password

Use this when the user already exists.

```json
{
  "id": "wallet-sign-in-01",
  "resource": "sign-in",
  "tokenize": {
    "custom_claim_fields": ["id", "email"],
    "type": "JWT",
    "algorithm": "HS256",
    "expiration": 86400,
    "encryption_key": "$ENV.JWT_SECRET_KEY",
    "property_name": "token"
  },
  "actionables": [
    {
      "id": 1,
      "mode": "QUERY",
      "payload_validation": [
        {
          "field": {
            "email": {
              "type": "EMAIL"
            }
          },
          "max_length": 255
        },
        {
          "field": {
            "password": {
              "type": "STRING"
            }
          },
          "min_length": 8,
          "max_length": 255
        }
      ],
      "sql_query": {
        "query": "SELECT id, name, email, password FROM users WHERE email = $1 AND deleted_at IS NULL",
        "parameters": ["email"]
      },
      "verify_hashables": [
        {
          "property": "password",
          "algorithm": "BCRYPT"
        }
      ],
      "returnables": ["id", "name", "email"]
    }
  ]
}
```

### Pattern 3. Read the current user profile

Use this when the client needs a protected profile endpoint.

```json
{
  "id": "wallet-profile-01",
  "resource": "profile",
  "tokenize": {
    "type": "JWT",
    "algorithm": "HS256",
    "encryption_key": "$ENV.JWT_SECRET_KEY"
  },
  "protected": {
    "provide_as": "x-access-token",
    "extract_claims": ["id"]
  },
  "actionables": [
    {
      "id": 1,
      "mode": "QUERY",
      "sql_query": {
        "query": "SELECT id, name, email, wallet_balance FROM users WHERE id = $1 AND deleted_at IS NULL",
        "parameters": ["$PROTECTED.id"]
      },
      "returnables": ["id", "name", "email", "wallet_balance"]
    }
  ]
}
```

### Pattern 4. Update the current user profile

Use this when you need a safe first write behind auth.

```json
{
  "id": "wallet-update-profile-01",
  "resource": "update-profile",
  "tokenize": {
    "type": "JWT",
    "algorithm": "HS256",
    "encryption_key": "$ENV.JWT_SECRET_KEY"
  },
  "protected": {
    "provide_as": "x-access-token",
    "extract_claims": ["id"]
  },
  "actionables": [
    {
      "id": 1,
      "mode": "QUERY",
      "sql_query": {
        "query": "UPDATE users SET name = $1, updated_at = $2::timestamptz WHERE id = $3 AND deleted_at IS NULL RETURNING id, name, email, wallet_balance",
        "parameters": ["name", "$DATETIME", "$PROTECTED.id"]
      },
      "returnables": ["id", "name", "email", "wallet_balance"]
    }
  ]
}
```

If you need soft delete behavior next, pair this with [Extras](/sub0/extras.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://docs.lingoql.com/sub0/apis-abi/practical-examples/wallet-backend-auth-and-accounts.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.
