# How to sign customers in on your website

Sign customers in before letting them view their sessions or act on their Podyx bookings. Your website owns its customer session. Your backend uses a studio API key to call the Studio API on the signed-in customer's behalf.

## Set up your backend

Configure your studio's Podyx storefront host and keep the studio API key on your server. Keep a server-side association between each website account and its Podyx client ID for that studio. Use this association for authorization whenever a customer asks to view or change a booking. [Studio API access and permissions](/api/docs/guides/v2/access)

## Sign in with a Podyx email and password

1. Send the customer's email and password from your sign-in form to your backend over HTTPS. Exclude the credentials and login response from application logs.
2. Have your backend send `POST /api/auth/login` with the same JSON fields to the Podyx **studio storefront host**. This is the separate password auth endpoint. It takes the customer's credentials and does not require a studio API key.
3. On HTTP `200`, use `user.id` from the response to identify the Podyx client. Create your website session on the server and keep the returned Podyx user token out of browser storage if your backend needs to retain it.

Password sign-in requires a verified Podyx account with a password. A client created as an external account must activate their Podyx account before they can sign in to it. A user who signed up with Google may also need to set a password through Podyx first. [Client creation and account activation](/api/docs/guides/v2/clients)

## Sign in with Google on your website

1. Configure Google Sign-In for your own site and implement Google's OpenID Connect flow. On the backend, validate the ID token's signature, issuer, audience, expiration, and nonce where applicable. For a redirect flow, validate `state` before accepting the callback. [Google OpenID Connect guide](https://developers.google.com/identity/openid-connect/openid-connect)
2. Identify the Google account by its issuer and `sub` claim. Before the first email-based association, verify control of the mailbox. For an address Google is not authoritative for, use a fresh email challenge even if `email_verified` is true. A client creation or booking request can resolve to an existing Podyx user, including when its studio association is new. Before granting access to that person's records, verify control of their account through Podyx sign-in or a fresh email challenge. Store the resulting `client_id` against the Google identity and studio in your backend. [Google's email verification rules](https://developers.google.com/identity/gsi/web/guides/verify-google-id-token) · [Create a Podyx client](/api/docs#/Studio%20clients/v2CreateClient)
3. Create your website session. Before every Podyx call, authorize the requested record against the signed-in user's studio and stored client ID. For a new booking, use the current email of the linked Podyx client, fetched on your backend. Require fresh ownership proof before using a changed Google email to link a different client. For an existing booking, check that it belongs to the signed-in customer.

Podyx also offers Google sign-in on the studio's hosted `/login` page. That flow returns to the Podyx storefront and creates a storefront session. A separate website uses its own Google flow to establish its session.

## Verify sign-in and access

Use test customers to verify both that a signed-in customer can see their own sessions and that replacing a client or booking ID in a browser request gives them no access to another customer's record. Keep the response's user token separate from the studio key used to call the Studio API. [Read the client's sessions](/api/docs#/Studio%20operations/v2ListSessions)

| Result | What to check |
| --- | --- |
| `401 invalid_credentials` | Check the studio host and ask the customer to verify their credentials. This is also the response for a blocked account. |
| `403 email_not_verified` | Ask the customer to complete Podyx email verification before signing in again. |
| Google sign-in succeeds but no sessions appear | Check the studio and the stored Podyx client association. A Google account ID is separate from a Podyx client ID. |

## Example

Send a password sign-in request from your backend to the studio's Podyx host. The JSON values below are placeholders for the customer's input.

```http
POST /api/auth/login HTTP/1.1
Host: example-studio.podyx.com
Content-Type: application/json

{"email":"customer@example.test","password":"<customer password>"}
```

The response contains `token` and `user`, including `user.id`, `user.email`, and `user.is_verified`. Use `user.id` from the successful server response when associating the website session with the Podyx client.
