What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

How can I save multiple remix based custom app auth session in same database ?

Solved

How can I save multiple remix based custom app auth session in same database ?

anhdd_kuro
Tourist
5 0 0

For Remix-based custom apps that only using a database for storing sessions. I'm considering storing them in the same database but with different IDs.

Currently, all custom apps store sessions with the same ID 'offline_xxx.myshopify.com,' so they overwrite each other.

- First question:

Should I proceed with this approach?

- Second question:

How can I achieve this ?

 
Accepted Solution (1)

lanesky
Shopify Partner
2 1 1

This is an accepted solution.

The content at below link suggests that you can specify a custom table name for session storage. If you're managing multiple applications, it's feasible to create a separate table for each application to store their sessions.

 

https://github.com/Shopify/shopify-app-js/tree/main/packages/shopify-app-session-storage-prisma#cust...

 

View solution in original post

Replies 4 (4)

SBD_
Shopify Staff
1831 273 421

Hey @anhdd_kuro 

 

Out of the box that's going to be awkward because the template uses shopify-app-session-storage-prisma which expects a specific schema. If you wanted to try implementing your own session storage, there's a guide here: https://github.com/Shopify/shopify-app-js/blob/main/packages/shopify-app-session-storage/implementin...

 

 

Scott | Developer Advocate @ Shopify 

arifrahman
Shopify Partner
1 0 0

is there a way to add additional session params using this implementation?

markogill
Shopify Partner
16 3 5

You can extend the prisma schema by adding an additional Model that links to the first table by Shop. Something like this:

 

model Session {
  id              String    @Anonymous
  shop            String
  state           String
  isOnline        Boolean   @Default(false)
  scope           String?
  expires         DateTime?
  accessToken     String
  userId          BigInt?
}

model MyAppSession {
  id           String     @Anonymous
  shop         String
  someData     String
}

 

from here you can write your extended session based on the Shopify session

 

import db from "~/db.server";

const {session} = await authenticate.admin(request);

db.myAppSession.create({
      data: {
        id: session.id,
        shop: session.shop,
        someData: "extended session data",
      },
});
Developing Order Otter
https://apps.shopify.com/order-otter

Import PDF Purchases to your Store.

lanesky
Shopify Partner
2 1 1

This is an accepted solution.

The content at below link suggests that you can specify a custom table name for session storage. If you're managing multiple applications, it's feasible to create a separate table for each application to store their sessions.

 

https://github.com/Shopify/shopify-app-js/tree/main/packages/shopify-app-session-storage-prisma#cust...