Closed fonya2014 closed 1 year ago
Here too
I am experiencing this issue, too. Just set up session storage with mongodb using the @shopify/shopify-app-session-storage-mongodb
package
another one, I want to storage in mongodb
I ended up replacing validateAuthenticatedSession()
with a custom middleware function to retrieve the session from the shopify_sessions
collection. I'm then setting the session in the following responses. Things seem to be working fine and I don't see this problem anymore.
export const customMiddleware = async function (req, res, next) {
const session = await db.collection('shopify_sessions').findOne({ /** whatever index **/ })
res.locals.shopify = { session: {} }
res.locals.shopify.session = session
next()
}
Hello everyone! I investigated the issue and here is what I discovered:
MongoDB and Redis return the following object:
AuthScopes {
compressedScopes: Set(1) { 'write_themes' },
expandedScopes: Set(2) { 'write_themes', 'read_themes' }
}
The error
TypeError: scopesArray.map is not a function
happens because .map doesn't work with objects.
I tried to replace the line:
scopesArray = scopes;
width this line:
scopesArray = [...scopes.expandedScopes]
In this part of the code (In the file node_modules\@shopify\shopify-api\lib\auth\scopes\index.js):
function AuthScopes(scopes) {
var scopesArray = [];
if (typeof scopes === 'string') {
scopesArray = scopes.split(new RegExp("".concat(AuthScopes.SCOPE_DELIMITER, "\\s*")));
}
else if (scopes) {
//scopesArray = scopes;
scopesArray = [...scopes.expandedScopes]
}
And everything is working now
Hello everyone! I investigated the issue and here is what I discovered:
MongoDB and Redis return the following object:
AuthScopes { compressedScopes: Set(1) { 'write_themes' }, expandedScopes: Set(2) { 'write_themes', 'read_themes' } }
The error
TypeError: scopesArray.map is not a function
happens because .map doesn't work with objects.I tried to replace the line:
scopesArray = scopes;
width this line:scopesArray = [...scopes.expandedScopes]
In this part of the code (In the file node_modules@shopify\shopify-api\lib\auth\scopes\index.js):
function AuthScopes(scopes) { var scopesArray = []; if (typeof scopes === 'string') { scopesArray = scopes.split(new RegExp("".concat(AuthScopes.SCOPE_DELIMITER, "\\s*"))); } else if (scopes) { //scopesArray = scopes; scopesArray = [...scopes.expandedScopes] }
And everything is working now
Had exact same issue, saw the same output for scopesArray. Implemented the fix recommended in that reply and it all works. thanks @fonya2014
@paulomarg or @cquemin is this something that could be PR'd? Also, does using the expandedScopes
for the scopesArray cause problems or should we be combining the compressedScopes and expandedScopes, then use that array?
Try to remove shopify-api
dependency as answered here https://github.com/Shopify/shopify-app-template-node/issues/1208#issuecomment-1406999580
@fonya2014 I'm having difficulty in reproducing this as you've described above.
@shopify-app-express
@shopify/shopify-app-session-storage-mongodb
@shopify/shopify-api
MongoDB and Redis return the following object:
AuthScopes { compressedScopes: Set(1) { 'write_themes' }, expandedScopes: Set(2) { 'write_themes', 'read_themes' } }
Where did you log this object?
I'm using the basic templates with version 1.0.2
of the mongodb package (which was the version around the time this issue was created), and I've modified the mongodb.js
file such that it logs what's returned by findOne()
in loadSession()
...
async loadSession(id) {
await this.ready;
const result = await this.collection.findOne({
id
});
console.log('MongoDBSessionStorage.loadSession', id, result); // added this debug line
return result ? new shopifyApi.Session(result) : undefined;
}
The output I get is
MongoDBSessionStorage.loadSession offline_testshop.myshopify.com {
_id: new ObjectId("644933001151c713ce729762"),
id: 'offline_testshop.myshopify.com',
shop: 'testshop.myshopify.com',
state: '424763202963782',
isOnline: false,
scope: 'write_products,write_orders',
accessToken: 'shpat_redacted_access_token'
}
scope
is showing as a string, not an AuthScopes
object, so I'm curious as to where you logged that return value?
Note that I've also tried this with @shopoify/shopify-app-express@1.0.2
and @shopify/shopify-app-session-storage-mongodb@1.0.1
Hello @mkevinosullivan !
Here are the versions of packages I probably used at that time:
@shopify-app-express 1.0.2 @shopify/shopify-app-session-storage-mongodb 1.0.1 @shopify/shopify-api 6.1.0
I don't remember for sure about the mongodb and shopify-api packages as it was 4 months earlier and I updated all apps to recent versions since then.
I added the console log to this file: node_modules@shopify\shopify-api\lib\auth\scopes\index.js
function AuthScopes(scopes) {
var scopesArray = [];
console.log(scopes); // here is my console log
if (typeof scopes === 'string') {
scopesArray = scopes.split(new RegExp("".concat(AuthScopes.SCOPE_DELIMITER, "\\s*")));
}
else if (scopes) {
scopesArray = scopes;
}
And it showed me the following:
AuthScopes {
compressedScopes: Set(1) { 'write_themes' },
expandedScopes: Set(2) { 'write_themes', 'read_themes' }
}
As I can see, the changes done several days ago in this PR must address the issue: https://github.com/Shopify/shopify-api-js/pull/837
Released in @shopify/shopify-api@7.1.0
today.
# Issue summary
Hello everyone!
I am working with the new app template and the API that was released in January 2023.
I am trying to use Redis or MongoDB as session storage. I use these packages: @shopify/shopify-app-session-storage-redis' @shopify/shopify-app-session-storage-mongodb'
according to these guides: https://github.com/Shopify/shopify-app-js/tree/main/packages/shopify-app-session-storage-redis https://github.com/Shopify/shopify-app-js/tree/main/packages/shopify-app-session-storage-mongodb
And I am getting the following error in the console:
If I try to use REST API, I am getting the 503 error on the frontend (browser console).
The session data document is created in MongoDB.
If I use SQLiteSessionStorage, everything works and loads fine.
Could you please help me to solve the issue?
@shopify/shopify-app-express
version: 1.0.2My shopify.js file:
`
`
## Expected behavior
The session and scope loads from DB.
## Actual behavior
The following error in the console:
## Steps to reproduce the problem
Use Redis or MongoDB according to https://github.com/Shopify/shopify-app-js/tree/main/packages/shopify-app-session-storage-redis https://github.com/Shopify/shopify-app-js/tree/main/packages/shopify-app-session-storage-mongodb
Try to get access to the REST API using the app.