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?
Did you ever get this worked out? Removing Auth got me a little closer:
SESSION_STORAGE: new Shopify.Session.PostgreSQLSessionStorage(`${process.env.DATABASE_URL}?sslmode=require`),
But now i get
2022-08-01T00:21:05.291801+00:00 app[web.1]: node:internal/process/promises:288
2022-08-01T00:21:05.291820+00:00 app[web.1]: triggerUncaughtException(err, true /* fromPromise */);
2022-08-01T00:21:05.291821+00:00 app[web.1]: ^
2022-08-01T00:21:05.291821+00:00 app[web.1]:
2022-08-01T00:21:05.291822+00:00 app[web.1]: Error: self-signed certificate
2022-08-01T00:21:05.291823+00:00 app[web.1]: at TLSSocket.onConnectSecure (node:_tls_wrap:1534:34)
2022-08-01T00:21:05.291823+00:00 app[web.1]: at TLSSocket.emit (node:events:513:28)
2022-08-01T00:21:05.291823+00:00 app[web.1]: at TLSSocket._finishInit (node:_tls_wrap:948:8)
2022-08-01T00:21:05.291823+00:00 app[web.1]: at ssl.onhandshakedone (node:_tls_wrap:729:12) {
2022-08-01T00:21:05.291824+00:00 app[web.1]: code: 'DEPTH_ZERO_SELF_SIGNED_CERT'
2022-08-01T00:21:05.291824+00:00 app[web.1]: }
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.SESSION_STORAGE: new Shopify.Session.PostgreSQLSessionStorage("postgres://username:password@host/database")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.