Getting the session info when someone install my app

Getting the session info when someone install my app

Omar
Shopify Partner
3 0 0

I'm using @Shopify/shopify-app-session-storage-prisma to save the session into my DB.

 

When I try to install my app on a dev store using the Test app on development store section it doesn't call back to my server. And the session won't save.

 

Is this the case on public installation?

 

How do I save the session when someone install my app?

Replies 4 (4)

Tahidul_Islam
Shopify Partner
2 0 0

can you please provide your app storage config code snippet? FYI, you can use the following code snippet

import {shopifyApp} from '@shopify/shopify-app-express';
import {PrismaSessionStorage} from '@shopify/shopify-app-session-storage-prisma';
import {PrismaClient} from '@prisma/client';

const prisma = new PrismaClient();
const storage = new PrismaSessionStorage(prisma);

const shopify = shopifyApp({
  sessionStorage: storage,
  // ...
});

 

Also you can provide tablename as follows:

const storage = new PrismaSessionStorage(prisma, {
  tableName: 'MyCustomSession',
});

 

Please follow this link for better undestanding.

Omar
Shopify Partner
3 0 0

This is exactly my code, it works when using this URL https://my_server/api/auth?shop=THE_SHOP_URL, but my issue is that when I try to install a store (using Test app on development store) it doesn't call back to my server.

 

The fix I have right now is I have to use this URL https://my_server/api/auth?shop=THE_SHOP then it will call back my server and the session is saved.

 

 

my code:

const prisma = new PrismaClient()
const storage = new PrismaSessionStorage(prisma)

class StorageTest extends PrismaSessionStorage<PrismaClient> {
  constructor(prisma: PrismaClient) {
    super(prisma)
  }

  async storeSession(session: Session): Promise<boolean> {
    console.log('Got new session', session)
    return await super.storeSession(session)
  }
}

const t = new StorageTest(prisma)

const shopify = shopifyApp({
  api: {
    apiKey: process.env.SHOPIFY_API_KEY || '',
    apiSecretKey: process.env.SHOPIFY_API_SECRET || '',
    scopes: (process.env.SCOPES || DEFAULT_SCOPES).split(','),
    hostScheme: (process.env.SCHEMA as any) || 'http',
    hostName: process.env.HOST,
    apiVersion: ApiVersion.April24,
  },
  auth: {
    path: '/api/auth',
    callbackPath: '/api/auth/callback',
  },
  webhooks: {
    path: '/api/webhooks',
  },
  // sessionStorage: storage,
  sessionStorage: t
})
 
Tahidul_Islam
Shopify Partner
2 0 0

you can try the following code snippet

const prisma = new PrismaClient()
const storage = new PrismaSessionStorage(prisma)

const shopify = shopifyApp({
  api: {
    apiKey: process.env.SHOPIFY_API_KEY || '',
    apiSecretKey: process.env.SHOPIFY_API_SECRET || '',
    scopes: (process.env.SCOPES || DEFAULT_SCOPES).split(','),
    hostScheme: (process.env.SCHEMA as any) || 'http',
    hostName: process.env.HOST,
    apiVersion: ApiVersion.April24,
  },
  auth: {
    path: '/api/auth',
    callbackPath: '/api/auth/callback',
  },
  webhooks: {
    path: '/api/webhooks',
  },
  sessionStorage: storage
})
Omar
Shopify Partner
3 0 0

Thanks for your reply, I still don't get anything back after a user installs my app. No calls to /api/auth/callback. It works when using the auth URL (/api/auth?shop) but if I used the parter test store install it won't call back my server.