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

# Authentication

> Sign a diner in with a one-time login code so their cart can use and earn points.

Sign a diner in to use their points, addresses and past orders. Diners can still order as guests.

The Accounts API uses the same `X-Channel-Id` and `X-Session-Id` headers as the [Storefront API](https://help.atlas.kitchen/connect/storefront-api/authentication.md).

![Sequence: your app calls POST /accounts/v1/request\_otp, or POST /accounts/v1/signup if that returns 404. Atlas sends the diner a login code by WhatsApp or email. The diner enters the code, your app calls POST /accounts/v1/login, gets a new X-Session-Id, and uses it to call as the diner, such as PUT /cart/points.](https://mintcdn.com/atlaskitchen/BmQiOcoSVG0-IGbX/images/connect/accounts-sign-in.png?fit=max\&auto=format\&n=BmQiOcoSVG0-IGbX\&q=85\&s=ebad38e5d722f007f789d455dfceafb2)

Sign-in flow. The green step is only for a diner with no Atlas account.

## Sign in a diner who has an account

**1. Request a login code**

Call [Request login code](https://help.atlas.kitchen/connect/accounts-api/sign-in/request-login-code.md) with the diner's mobile number.

```bash theme={null}
curl https://api.atlas.kitchen/accounts/v1/request_otp \
  -H "X-Channel-Id: $CHANNEL_ID" -H "X-Session-Id: $SESSION_ID" \
  -H "Content-Type: application/json" \
  -d '{"mobile_number": "+6581000001"}'
```

`last_otp_delivery_mode` in the response says where the code went: `whatsapp` or `email`. Tell the diner where to look.

A new code replaces the last one, so only the latest code works. A number or email can get 5 codes in 10 minutes.

**2. Log in with the code**

Call [Log in](https://help.atlas.kitchen/connect/accounts-api/sign-in/log-in.md) with the same mobile number and the 6-digit code.

```bash theme={null}
curl -D - https://api.atlas.kitchen/accounts/v1/login \
  -H "X-Channel-Id: $CHANNEL_ID" -H "X-Session-Id: $SESSION_ID" \
  -H "Content-Type: application/json" \
  -d '{"mobile_number": "+6581000001", "otp": "043317"}'
```

After 5 wrong codes, log in stops working until the diner requests a new code.

Save the new `X-Session-Id` from the response headers and send it from now on. The old one stops working. The diner's cart moves to the new session, ready for [Toggle points](https://help.atlas.kitchen/connect/storefront-api/cart/toggle-points.md).

## Sign up a new diner

If [Request login code](https://help.atlas.kitchen/connect/accounts-api/sign-in/request-login-code.md) returns `404`, the diner has no Atlas account yet. A diner who already has one, from any Atlas merchant, gets a code straight away and can log in.

1. Call [Sign up](https://help.atlas.kitchen/connect/accounts-api/sign-in/sign-up.md) with their name, email and mobile number. It sends them a login code.
2. Call [Log in](https://help.atlas.kitchen/connect/accounts-api/sign-in/log-in.md) with that code.

The diner joins the merchant's point program when they log in for the first time.

## Points belong to the merchant

Each merchant has its own point program, so a diner's balance differs between merchants.

## Sign a diner out

Delete the saved `X-Session-Id` and call `GET /storefronts/v1/channel` without one. On shared devices such as kiosks, do this after every order.

## If it doesn't work

* **`422` `Please wait`**: a code was sent less than 30 seconds ago. Wait, then try again.
* **`429` `Too many codes requested`**: this number or email has had 5 codes in 10 minutes. Wait 10 minutes.
* **`429` `Too many wrong codes`**: 5 wrong codes were tried. Request a new code.
* **`422` `User Exists`** from Sign up: log the diner in instead.
* **`422` `otp` `is incorrect`**: wrong or expired code. Request a new one.
* **`401` `session_id`**: use the session ID from the login response.
* **`401` `login`**: no diner is signed in. Sign them in first.
* **`403` `mobile_number`**: the number isn't verified. Sign in with a code to verify it.


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