Hey again @Banibrata_Manna, happy to take a look at this with you.
To get user details and POS location data, you’ll need to use the lowercase global like this (a bit more info here):
// For user data:
const user = await shopify.user();
// For POS location (when in POS context):
if (shopify.environment.pos) {
const location = await shopify.pos.location();
}
Both of these methods return Promises, so you’d want to just make sure you’re handling them asynchronously.
Since you’re using TypeScript, you might also want to install the type definitions to avoid TypeScript errors in case that’s causing issues:
npm install --save-dev @shopify/app-bridge-types
One thing to check is that the App Bridge script is fully loaded before you try to access the shopify global. You can verify this by checking if typeof shopify !== 'undefined' before making any API calls.
If you need a bit more help, I’m happy to dig into this for sure, could you share what version of App Bridge you’re expecting to use (the CDN URL suggests you’re on the latest), what error messages you’re seeing in the console, and what the output is when you run console.log(window.shopify) in your app?
Hope this helps - let me know if I can dig into this more with you, happy to help out.
Hey @Alan_G , I got the shopify global object from useAppBridge of @shopify/app-bridge-react library, I can log it successfully but when I do: await shopify.user() and run my app on admin then promise stays in pending state forever.
Thanks @Banibrata_Manna, that is strange. Can you let me know which version of the App Bridge packages you’re using? (npm list @shopify/app-bridge) and are you seeing any console errors before the promise hangs (please share if so!)?
I think my next step here is to touch base with the product team to investigate further, but just wanted to follow up in case it’s potentially a version mismtach issue. Hope to speak soon!
I think I see the issue here. It looks like you’re using App Bridge v3.7.10 but using v4 API patterns ( for example, the shopify.user() method is only available in v4).
For v3, you’ll need to use [getState()] instead: const state = await [appBridge.getState(); const user = state.staffMember;
The lowercase shopify global doesn’t exist in v3, which is likely why your promise is hanging - if you want to use those newer API patterns, you’d need to upgrade to App Bridge v4. Let me know if this helps get you unstuck, hope this helps!
And I’m not using remix framework or shopify CLI at all. Isn’t there a way to do all these without using the react library.
My App is basically a PW App which takes the session token from app bridge and passes it to my backend to validate and syncs the user’s ID from the token to backend and issues a a JWT Token that will be used for any future API calls to my backend. And Using the issued JWT token user logs in other PW Apps and use that same token for it’s api calls.
The app is working fine, I just don’t have the POS user details and POS Location ID and I only need them to complete my flow.
And my Project Plan doesn’t include remix-framework, Shopify CLI and just use the app-bridge-library and if it is really needed then I can also keep the app-bridge-react library.
Though I’ll try with latest dependency of shopify-app-react library.
Please help me out here, POS User and Location is the only thing left in my plan, rest is done.
Hey @Banibrata_Manna, thanks for the additional context. I think I’ve figured out what’s happening here after chatting with our App Bridge team.
The issue does appear to be related to how you’re mixing different major of our App Bridge libraries, which is causing the promise to hang. It looks like you’ve got v3 of app-bridge and v4 of app-bridge-react, and they’re essentially just not working well together there.
When you’re using useAppBridge() from the React library (v4), it’s expecting to work with App Bridge v4’s global shopify object, but you’re initializing with v3’s createAppBridge.
Our recommendation at the moment would be to upgrade everything to v4. You’d want to update your dependencies to something like:
"@shopify/app-bridge-react": "^4.2.0"
Then, uninstall @shopify/app-bridge from your project and instead of using createAppBridge from v3, you’d initialize using the v4 CDN approach. Add this script tag to your HTML as the first script in <head>:
Glad to hear things are solved for you on this one @Banibrata_Manna - I’ll take a look at your other question there and see if I can help there as well