Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Re: TypeError: Cannot read properties of undefined (reading 'MongoDBSessionStorage')

Solved

TypeError: Cannot read properties of undefined (reading 'MongoDBSessionStorage')

AnswerBook
Shopify Partner
17 0 4

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);

 

 

 

 

 

Accepted Solution (1)

herchu
Shopify Partner
4 1 4

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

 

View solution in original post

Replies 6 (6)

herchu
Shopify Partner
4 1 4

Hi,

Same here. Have you found a solution? 

It doesn't work even with a local MongoDB server.

 

 

herchu
Shopify Partner
4 1 4

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

 

AnswerBook
Shopify Partner
17 0 4

That worked, thank you! I am having trouble accessing that Discord channel, would you be able to share the name?

herchu
Shopify Partner
4 1 4

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.

CRISBIO
Visitor
2 0 1

hello, could you share the solution again? I enter discord but it doesn't come out.
Thank you so much

herchu
Shopify Partner
4 1 4

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"
),
...