How to get session token in shopify appbridge react v4

AlexLew
Visitor
1 0 0
import createApp from "@shopify/app-bridge";
import { getSessionToken } from "@shopify/app-bridge/utilities";

const app = createApp({
  apiKey: "12345",
});


const sessionToken = await getSessionToken(app);


How can i get this session token in App Bridge React v4?

Replies 5 (5)

ericute
Shopify Partner
57 4 7

I'm having the same issue too after upgrading to v4 just to get the Modal working.

ericute_0-1710174724359.png

 

BrainStation23
Shopify Partner
344 54 51

Hello,

@Shopify/app-bridge/utilities package is deprecated  https://www.npmjs.com/package/@shopify/app-bridge-utils

Instead of using this, You find everything on app state https://www.npmjs.com/package/@shopify/app-bridge

App State

Once the app is set up, you can access additional details and the state of the app at any time by making async call app.getState():

app.getState().then((state) => { console.info('App State:', state); });

Brain Station 23 PLC
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
Email: js.team@brainstation-23.com
ericute
Shopify Partner
57 4 7

Okay, so I can't install shopify/app-bridge and shopify/app-bridge-react without shopify/app-bridge-utils.

 

Here's what I have in my package.json.

ericute_0-1710294282998.png

 

Now I am getting a Module Not Found error:

ericute_1-1710294595337.png

 

ericute
Shopify Partner
57 4 7

I got it wrong. There's no @Shopify/app-bridge v4, that's for app-bridge-react. 

3ux1n3
Shopify Partner
13 0 1

in app bridge react 4 with the app bridge JS tag added to your index.html you don't need that session token since all fetch calls are wrapped and add that token automatically however if you still need it you can use this : 
https://shopify.dev/docs/api/app-bridge-library/apis/id-token

where shopify is the variable u get this way : 
const shopify = useAppBridge()