A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I am having issues setting up session storage with MongoDB for my app and getting the TypeError described in the title.
After referring to the Read.me and shopify-api-node/src/auth/session/storage at main · Shopify/shopify-api-node (github.com) I configured the Shopify.Context.initialize SESSION_STORAGE for a MongoDB database. I have tried both methods, withCredentials and without. I can see in my GUI for MongoDB there is some connection happening regardless of the error. I have also verified that I can connect to the DB with those same credentials but outside of the Shopify.Auth.Session.MongoDBSessionStorage method.
Has anyone else had this issue? I'm not sure what else to do.
// This should be replaced with your preferred storage strategy
// SESSION_STORAGE: Shopify.Auth.Session.MongoDBSessionStorage.withCredentials(
// "cluster0.xyz123.mongodb.net",
// "DBName",
// "verified_username",
// "verified_password"
// ),
SESSION_STORAGE: new Shopify.Auth.Session.MongoDBSessionStorage(
"mongodb+srv://verified_username:verified_password@cluster0.xyz123.mongodb.net/?retryWrites=true&w=majority",
"DBName"
),
// I also tried a different version of the connecting url that was closer to the documentation: mongodb://verified_username:verified_password@cluster0.xyz123.mongodb.net/
// Verified Connection in the same index.js by use of console.log() and monitoring DB
import { MongoClient, ServerApiVersion } from "mongodb";
const uri =
"mongodb+srv://verified_usernmae:verified_password@cluster0.xyz123.mongodb.net/?retryWrites=true&w=majority";
const client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
serverApi: ServerApiVersion.v1,
});
async function run() {
try {
await client.connect();
// perform actions on the collection object
await client.db("admin").command({ ping: 1 });
console.log("Connected successfully to server");
} finally {
await client.close();
}
}
run().catch(console.dir);
Solved! Go to the solution
This is an accepted solution.
Get rid of Auth. Just use Shopify.Session.MongoDBSessionStorage
The solution is from another dev in Discord:
https://discord.com/channels/842813079926603828/851506171377614858/1001542244207169657
Hi,
Same here. Have you found a solution?
It doesn't work even with a local MongoDB server.
This is an accepted solution.
Get rid of Auth. Just use Shopify.Session.MongoDBSessionStorage
The solution is from another dev in Discord:
https://discord.com/channels/842813079926603828/851506171377614858/1001542244207169657
That worked, thank you! I am having trouble accessing that Discord channel, would you be able to share the name?
The server is https://discord.gg/Djmr4Psb
The channels I normally browse are building-apps, dev-talk, and developer-experience, and a couple of others.
hello, could you share the solution again? I enter discord but it doesn't come out.
Thank you so much
As far as I can see, the new Shopify's JS library changed a lot. See here:
https://github.com/Shopify/shopify-app-js/tree/main/packages/shopify-app-session-storage-mongodb
If you are using the old version, just delete the '.Auth' in the sample code.
Like from this:
...
SESSION_STORAGE: new Shopify.Auth.Session.MongoDBSessionStorage(
"mongodb+srv://etc-etc-etc", "DBName"
),
...
to this:
...
SESSION_STORAGE: new Shopify.Session.MongoDBSessionStorage(
"mongodb+srv://etc-etc-etc", "DBName"
),
...