I’m trying to get a session token so I can secure my network requests in my POS Extension. The problem is that when I try to run the simple example in the documentation the sessionToken is always null. I am able to get the currentSession data in both my own code and the example.
Here is the specific example.
import React, {useState} from 'react';
import {
reactExtension,
useApi,
Screen,
Text,
} from '@shopify/ui-extensions-react/point-of-sale';
const SmartGridModal = () => {
const {currentSession, getSessionToken} =
useApi<'pos.home.modal.render'>().session;
const {shopId, userId, locationId, staffMemberId} = currentSession;
const [sessionToken, setSessionToken] = useState<string>();
getSessionToken().then((newToken) => {
setSessionToken(newToken);
});
return (
<Screen name="ScreenOne" title="Screen One Title">
<Text>
shopId: {shopId}, userId: {userId}, locationId: {locationId}, staffId:
{staffMemberId}
</Text>
<Text>sessionToken: {sessionToken}</Text>
</Screen>
);
};
export default reactExtension('pos.home.modal.render', () => (
<SmartGridModal />
));