Generate custom token using JWT

Topic summary

A developer is building a Shopify Remix app and needs to generate custom JWT tokens during store installation, storing them alongside shop names and emails in a Prisma database.

Proposed implementation steps:

  • Define a Prisma Store model with fields for shop, email, and token
  • Install the jsonwebtoken npm library
  • Create a utility function to generate JWT tokens using the shop name
  • Handle the Shopify OAuth callback by:
    • Extracting shop and access_token
    • Fetching store email via Shopify Admin API
    • Generating JWT and storing all data using prisma.store.upsert()
  • Store JWT_SECRET securely in environment variables
  • Use the JWT for authenticating future store requests

The discussion remains open for follow-up questions as the developer implements this solution.

Summarized with AI on October 28. AI used: claude-sonnet-4-5-20250929.

Hi Shopify Community,

I’m working with a Shopify Remix app. When a store installs the app, I want to generate a custom token using JWT and store it along with the store’s name and associated email in a Prisma database table. What are the main steps to implement this?

Hi @Sneha_Subhash ,

Main steps to implement Prisma database table :-

  1. Define Prisma model
    Create a Store model with fields: shop, email, and token.

  2. Install JWT library
    npm install jsonwebtoken

  3. Create JWT utility
    Write a function to generate a JWT token using the store’s shop name.

  4. Handle Shopify OAuth callback
    In your callback route:

Extract shop and access_token.

Use the token to fetch the store’s email from the Shopify Admin API.

Generate a JWT using the shop.

Store shop, email, and the JWT in the database via prisma.store.upsert().

  1. Secure and verify
    Store JWT_SECRET in .env.

Use the JWT to authenticate future requests from the store.

Implement these steps and let me know if you need further assistance .

Thanks !

1 Like