Closed Michael-Gibbons closed 1 year ago
So I don't have a good solution to this issue but I do have a bad one, I am now checking for a 403 response when the app is rendered. Below is the relevant part of my _app.js
file generated by the shopify-cli.
function MyProvider(props) {
const app = useAppBridge();
if (typeof window !== "undefined") {
window.app = app;
//authFetch is just a fetch wrapper that adds the bearer token header,
// you can slot this in for any authenticated request system you have set up,
//authenticatedFetch from app-bridge-utils for example
// the "state" endpoint is specific to my application but this can be any request as long as the request won't return a 403 in any other scenario than this,
// I would recommend creating a custom endpoint which always returns 200
authFetch("/state").then((response) => {
if (response.status == 403) {
window.location.href = "/auth?shop=YOUR-STORE.myshopify.com";
}
});
}
const client = new ApolloClient({
fetch: userLoggedInFetch(app),
fetchOptions: {
credentials: "include",
},
});
const Component = props.Component;
return (
<ApolloProvider client={client}>
<StoreProvider store={store}>
<Component {...props} />
</StoreProvider>
</ApolloProvider>
);
}
Note that this repo is no longer maintained and this issue will not be reviewed. Prefer the official JavaScript API library. If you still want to use Koa, see simple-koa-shopify-auth for a potential community solution.
First I'd like to apologize if I'm simply not understanding something, I've been working on this for days and have scoured all resources I could find so if anyone can help I would be very appreciative.
Issue summary
When our app is freshly deployed, Staff member 1 goes to our embedded app in the Shopify admin. Staff member 1 goes through the Oauth process, a session is created and stored in a db.
Requests work as expected and are authenticated.
Staff member 2 goes to the app in the Shopify admin using a different account and requests are forbidden as they do not have a session access token, redirecting to the /auth route manually fixes this issue as a session is created for them.
Expected behavior
Staff member 2 should be redirected to the Oauth flow to have a session created for them.
Actual behavior
Requests are 403 forbidden and no Oauth flow is initiated
loadCallback
fires, sees there is no session in the db corresponding to this user, and returns undefined. Nothing happens after this point.Reduced test case