shopify-app-template-node
shopify-app-template-node copied to clipboard
CustomSessionStorage failed to find sessions by shop. Error Details: findSessionsByShopCallback not defined.
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.
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:
"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.
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.
I am getting the same error after using Redis CustomSessionStorage, and I really don't want to change the DB currently
Try to use RedisSessionStorage instead of CustomSessionStorage. @JohnYacoub
@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
Yes, I tried but it wasn't working. Let us know if you find any solution regarding findSessionsByShopCallback . Thanks. @JohnYacoub
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 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
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
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
just don't use CustomSessionStorage.
@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 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);
}
}