I’m working to set up PostgresSQL Session Storage for my Shopify app using the direct Shopify documentation
They say to set up Session Storage like so:
import Shopify from '@shopify/shopify-api';
Shopify.Context.initialize({
SESSION_STORAGE: new Shopify.Auth.Session.PostgreSQLSessionStorage("postgres://username:password@host/database"),
...
});
// OR
Shopify.Context.initialize({
SESSION_STORAGE: Shopify.Auth.Session.PostgreSQLSessionStorage.withCredentials(
"host.com",
"thedatabase",
"username",
"password",
),
...
});
However, when I set it up, I run into the following error:
Property 'Session' does not exist on type '{ SESSION_COOKIE_NAME: string; beginAuth(request: IncomingMessage, response: ServerResponse, shop: string, redirectPath: string, isOnline?: boolean | undefined): Promise<...>; ... 4 more ...; getCurrentSessionId(request: IncomingMessage, response: ServerResponse, isOnline?: boolean | undefined): string | undefined; }'.ts(2339)
}
My server crashes because: TypeError: Cannot read properties of undefined (reading 'PostgreSQLSessionStorage')
I’ve tried importing PostgreSQLSessionStorage
directly for use like so:
import { PostgreSQLSessionStorage } from "@shopify/shopify-api/dist/auth/session/index.js";
But that runs into a whole host of other undefined object issues.
Any idea where I’m going wrong?
2
Answers
Did you ever get this worked out? Removing Auth got me a little closer:
But now i get
Inquisitive Tom solution worked for me as well. To wrap it up, in order to switch to heroku postgresql from sqlite (original shopify CLI db), you have to:
Shopify.Context.initialize
inside index.js (be careful to replace all variables: username, password, host, database). Don’t include "auth" as opposed to what is shown in Shopify Doc.