-
-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No AppBridge context provided. #18
Comments
I ended up rolling back to my old
And things are working, I guess sometimes the |
Hmm that is really strange, I have not seen this issue myself yet. Which version of Next/React, Polaris & AppBridge are you using? |
From
I think I updated the version after I ran into the problem with the original example code. I will do more diagnosing when I get some time, I guess it is the following: in
Maybe it is working as intended and I should have a |
For me, I was getting an error that no i18n was provided. I put the ShopifyAppBridgeProvider within the AppProvider and it worked again: |
I've run into a similar issue using https://github.com/ctrlaltdylan/shopify-session-tokens-nextjs as the template for the site and It appears that the page being loaded flashes briefly without the App bridge loaded, causing any app bridge dependent components to throw an error such as the one above:
It's my understanding that:
Inside A bit of an aside but another issue I ran into is shopify's confusing naming system of their libraries:
|
I'm having the same issue with |
This seems to work for me.
As per Next.js documentation by using |
Did anyone found a better solution to this? So if I replace import React, { useEffect, useState } from "react";
import { useApi, useShopOrigin } from 'shopify-nextjs-toolbox';
export default function Home() {
const shopName = useShopOrigin();
const api = useApi();
const [response, setResponse] = useState(false);
// the session token is now available for use to make authenticated requests to the our server
useEffect(() => {
api.get("/api/verify-token")
.then((res) => {
setResponse(res.data);
})
.catch((res) => {
console.log(res);
});
}, []);
return (
<div className="container">
<div className="card">
<h2>Current Decoded Session Token</h2>
<p>
This is the decoded session token that was sent to the server after the OAuth handshake finished.
</p>
<p>
You can use the backend middleware <code>withSessionToken</code> to verify the API request came from the currently logged in shop
</p>
<p>
Wrap your API route with <code>withSessionToken</code> to access the shop's origin (a.k.a the shop's name in <code>shop-name.myshopify.com</code> format) in the backend.
</p>
<pre>
{JSON.stringify(response, null, 4)}
</pre>
</div>
<div className="card">
<h2>Currently logged in as</h2>
<code>{shopName}</code>
</div>
</div>
)
} To this: import React, { useEffect, useState } from 'react';
import { useApi, useShopOrigin } from 'shopify-nextjs-toolbox';
import { Card, EmptyState, Page, Layout, TextContainer, Image, Stack, Link, Heading, Loading, SkeletonBodyText } from '@shopify/polaris';
import { TitleBar, useNavigate } from '@shopify/app-bridge-react';
export default function Home() {
const shopName = useShopOrigin();
const api = useApi();
const [response, setResponse] = useState(false);
// the session token is now available for use to make authenticated requests to the our server
useEffect(() => {
api
.get('/api/verify-token')
.then((res) => {
setResponse(res.data);
})
.catch((res) => {
console.log(res);
});
}, []);
return (
<Page>
<TitleBar title="Home" />
<Layout>
<Layout.Section>
<Card>
<Card.Section>
<div className="card">
<h2>Current Decoded Session Token!</h2>
<p>This is the decoded session token that was sent to the server after the OAuth handshake finished.</p>
<p>
You can use the backend middleware <code>withSessionToken</code> to verify the API request came from the currently logged
in shop
</p>
<p>
Wrap your API route with <code>withSessionToken</code> to access the shop's origin (a.k.a the shop's name in{' '}
<code>shop-name.myshopify.com</code> format) in the backend.
</p>
<pre>{JSON.stringify(response, null, 4)}</pre>
</div>
<div className="card">
<h2>Currently logged in as</h2>
<code>{shopName}</code>
</div>
</Card.Section>
</Card>
</Layout.Section>
</Layout>
</Page>
);
} the issue immediately starts. I wonder if this has something to do with how NextJS generates pages, possibly compiling the page in a way that is incompatible with Polaris. Disabling Automatic Static Optimization as mentioned by @Jore unfortunately doesn't fix this. Is shopify-nextjs-toolbox fundamentally incompatible with Polaris for the application pages? Is that why @ctrlaltdylan created his own components for the landing page rather than using the ones provided by Polaris? |
Thank you for your amazing work, I couldn't do my own API routing with Shopify's CLI server.
I tried using in
home.js
:But I get the error:
Error: No AppBridge context provided. Your component must be wrapped in the <Provider> component from App Bridge React.
ShopifyAppBridgeProvider
should do the job looking at the source code. Maybe I just did something wrong.The text was updated successfully, but these errors were encountered: