shopify-app-template-node icon indicating copy to clipboard operation
shopify-app-template-node copied to clipboard

CustomSessionStorage failed to find sessions by shop. Error Details: findSessionsByShopCallback not defined.

Open dani-sanomads opened this issue 2 years ago • 6 comments

Issue summary

I'm using CustomSessionStorage with storeCallback, deleteCallback and loadCallback. I'm getting : CustomSessionStorage failed to find sessions by shop. Error Details: findSessionsByShopCallback not defined. I'm using postgres as a DB and server setup is in TS. I'm getting the session values in the DB but not sure about this error message. Screen Shot 2022-08-09 at 3 58 26 PM

Secondly, I'm also getting the error of cookies and I'm not getting the display of my app. I keeps on loading and then i get this message: Screen Shot 2022-08-09 at 3 56 08 PM

dani-sanomads avatar Aug 09 '22 11:08 dani-sanomads

"vite-plugin-react can't detect preamble. Something is wrong." After defining the findSessionsByShopCallback(). I finally got this on the frontend console. Maybe something wrong with the session on the frontend or I'm missing something.

dani-sanomads avatar Aug 11 '22 07:08 dani-sanomads

Instead of using the CustomSession Storage. I'm going to use the PostgresSessionStorage because it works fine with vitejs. Maybe we can close this issue or we can wait for CustomSessionStorage updates for findSessionsByShopCallback() docs. Thanks.

dani-sanomads avatar Aug 11 '22 07:08 dani-sanomads

I am getting the same error after using Redis CustomSessionStorage, and I really don't want to change the DB currently

JohnYacoub avatar Sep 05 '22 00:09 JohnYacoub

Try to use RedisSessionStorage instead of CustomSessionStorage. @JohnYacoub

dani-sanomads avatar Sep 05 '22 19:09 dani-sanomads

@dani-sanomads It seems that you will have to implement the function "findSessionsByShopCallback" , I found it a brief here https://github.com/Shopify/shopify-api-node/blob/main/docs/usage/customsessions.md

JohnYacoub avatar Sep 05 '22 21:09 JohnYacoub

Yes, I tried but it wasn't working. Let us know if you find any solution regarding findSessionsByShopCallback . Thanks. @JohnYacoub

dani-sanomads avatar Sep 05 '22 21:09 dani-sanomads

encounter this error CustomSessionStorage failed to find sessions by shop. Error Details: findSessionsByShopCallback not defined. while implementing mongodb too.

I found that the findSessionsByShopCallback is optional in the .

How can we fix it or how can we implement mongodb in shopify app.

jeff0723 avatar Sep 29 '22 08:09 jeff0723

@jeff0723 I think that findSessionsByShopCallback is no longer optional because the latest node template uses this method to figure out whether the request being sent to your server contains an authorized shop so you will have to either implement it in your custom session storage module or simply use the the existing SessionStorage options provided by shopify which handle this for you

SilasGrygier avatar Sep 29 '22 15:09 SilasGrygier

While findSessionsByShopCallback and deleteSessionsCallback are optional from the @shopify/shopify-api library's perspective, they're not optional when using this template.

I'm adding a note to the web/index.js file to highlight this ... https://github.com/Shopify/shopify-app-template-node/pull/1106

mkevinosullivan avatar Oct 11 '22 20:10 mkevinosullivan

Im going mental with this issue, i've done everything correctly and I still get this message :argh:

findSessionsByShopCallback failed to find sessions by shop. Error Details: findSessionsByShopCallback not defined.

Crazy part is that I defined this function and called in also on the CustomSessionStorage lol

alexandrosk avatar Nov 14 '22 15:11 alexandrosk

just don't use CustomSessionStorage.

jeff0723 avatar Nov 14 '22 15:11 jeff0723

@jeff0723 I was going crazy because I wanted to make it work with redis upstash, turns out if you use railway or any other redis with the RedisSession it just works lol -.-

alexandrosk avatar Nov 14 '22 18:11 alexandrosk

@alexandrosk the CustomSessionStorage constructor takes in the values at specific positions. findSessionsByShopCallback bind should be the last one in the instance call

...
SESSION_STORAGE: new Shopify.Session.CustomSessionStorage(
    sessionStorage.storeCallback.bind(sessionStorage),
    sessionStorage.loadCallback.bind(sessionStorage),
    sessionStorage.deleteCallback.bind(sessionStorage),
    sessionStorage.deleteSessionsCallback.bind(sessionStorage),
    sessionStorage.findSessionsByShopCallback.bind(sessionStorage)
  ),
  ...

then you can add the callbacks to the redis class like this

  async findSessionsByShopCallback(id) {
    try {
      let reply = await this.client.get(id);
      if (reply) {
        return [JSON.parse(reply)];
      } else {
        return [];
      }
    } catch (err) {
      throw new Error(err);
    }
  }

  async deleteSessionsCallback(ids) {
    try {
      let promises = [];
      ids.forEach((id) => {
        promises.push(this.client.del(id));
      });
      await Promise.all(promises);
      return true;
    } catch (error) {
      throw new Error(err);
    }
  }

benkissi avatar Dec 01 '22 13:12 benkissi