Skip to main content

Installation

npm install @shopify/shopify-app-react-router

shopifyApp()

Creates an object your app will use to interact with Shopify in a React Router application.

Function Signature

function shopifyApp<
  Config extends AppConfigArg<Storage, Future>,
  Storage extends SessionStorage,
  Future extends FutureFlagOptions = Config['future']
>(appConfig: Readonly<Config>): ShopifyApp<Config>

Configuration

appConfig
AppConfigArg
required
Configuration options for your Shopify app

Return Value

Returns a ShopifyApp object with the following properties:
sessionStorage
SessionStorage
The SessionStorage instance you passed in as a config option
addDocumentResponseHeaders
(request: Request, headers: Headers) => void
Adds required Content Security Policy headers for Shopify apps to the given Headers object
registerWebhooks
(options: RegisterWebhooksOptions) => Promise<RegisterReturn | void>
Register shop-specific webhook subscriptions using the Admin GraphQL API
authenticate
object
Methods for authenticating requests from different Shopify surfaces
unauthenticated
object
Methods for creating contexts from non-Shopify requests
login
(request: Request) => Promise<LoginError | never>
Log a merchant in and redirect them to the app root. Not available when distribution is AppDistribution.ShopifyAdmin.Returns: LoginError object with validation errors, or redirects on success

Example Usage

// app/shopify.server.ts
import { shopifyApp } from "@shopify/shopify-app-react-router/server";
import { PrismaSessionStorage } from "@shopify/shopify-app-session-storage-prisma";
import { ApiVersion } from "@shopify/shopify-api";
import prisma from "~/db.server";

const shopify = shopifyApp({
  apiKey: process.env.SHOPIFY_API_KEY!,
  apiSecretKey: process.env.SHOPIFY_API_SECRET!,
  scopes: process.env.SCOPES?.split(",")!,
  appUrl: process.env.SHOPIFY_APP_URL!,
  apiVersion: ApiVersion.October24,
  sessionStorage: new PrismaSessionStorage(prisma),
});

export default shopify;
export const authenticate = shopify.authenticate;

Key Differences from Remix Adapter

The React Router adapter is optimized for React Router v7+ and includes:
  1. Token Exchange by Default: Uses the token exchange authentication strategy by default (vs. auth code flow in Remix)
  2. POS Authentication: Includes authenticate.pos() for POS UI extension support
  3. Line Item Billing: Supports the newer line item billing format for complex billing structures
  4. React Router Integration: Built for React Router v7+ with appropriate type imports from react-router

Exported Types

export {
  LogSeverity,
  DeliveryMethod,
  BillingInterval,
  BillingReplacementBehavior,
  ApiVersion,
  Session,
  AppDistribution,
  LoginErrorType,
} from "@shopify/shopify-app-react-router/server";

export type {
  JwtPayload,
  ShopifyApp,
  LoginError,
} from "@shopify/shopify-app-react-router/server";

See Also

Build docs developers (and LLMs) love