> For the complete documentation index, see [llms.txt](https://docs.onside.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.onside.io/sdk/products-and-subscriptions/regions-and-storefronts.md).

# Regions & Storefronts

How OnsideKit resolves the user's region and storefront before and after login, and how that affects product availability and pricing.

Product availability and pricing vary by region. OnsideKit resolves a region for every products request and exposes the authenticated region as the **storefront**.

## How the region is resolved

### When logged in

The region is the **account's region** — the most accurate source of truth. It is exposed as `Onside.defaultPaymentQueue().storefront?.countryCode`. Once the user is logged in, this always wins; a pre-login hint (below) is ignored.

### When logged out

OnsideKit estimates the region:

1. The `onsideDefaultCountryCodeAssumption()` delegate hint, if you provide one.
2. Otherwise, the device's system region.

```swift
extension AppDelegate: OnsideDelegate {
    func onsideDefaultCountryCodeAssumption() -> String? {
        // An ISO 3166-1 alpha-2 code, e.g. "US", "DE", "GB".
        return userKnownRegion   // or nil to fall back to the device region
    }
}
```

{% hint style="info" %}
`onsideDefaultCountryCodeAssumption()` is the only hook that influences the region, and only **before** login. Provide it when your app already knows the user's likely region (from their profile or settings) so logged-out pricing is accurate. See [The Onside Delegate](/sdk/customization/delegate.md).
{% endhint %}

## The storefront

```swift
struct OnsideStorefront {
    var id: String
    var countryCode: String
}
```

`Onside.defaultPaymentQueue().storefront` is `nil` until the user logs in, then reflects the account's region. It changes when the user logs in or out, or their region changes.

## Best practice: fetch before login, then re-fetch

You can and should [fetch products](/sdk/products-and-subscriptions/fetching-products.md) before the user authenticates, so your store UI is ready immediately. Because the true region is only known after login, **re-fetch your products whenever the storefront changes**.

For external profiles, a refresh also removes subscriptions and non-consumables from the catalog and reports them in `unsupportedProductIdentifiers`. Account changes can affect the available product types even if the country stays the same.

Observe the storefront with a transaction observer:

```swift
func onsidePaymentQueueDidChangeStorefront(_ queue: OnsidePaymentQueue) {
    // The region may have changed — refresh prices/availability.
    reloadProducts()
}
```

See [Authentication & User Account](/sdk/core-concepts/authentication.md) for the full observer setup.

## Purchase protection on region change

If a user starts a purchase for a product fetched in one region but their account turns out to be in another, OnsideKit does **not** silently charge the new price. The queued purchase is gated so you can confirm the change with the user or cancel it. This is handled by the payment queue delegate — see [Handling Storefront & Price Changes](/sdk/purchasing/storefront-price-changes.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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.onside.io/sdk/products-and-subscriptions/regions-and-storefronts.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
