koa-shopify-auth
koa-shopify-auth copied to clipboard
Redirect after invalid token and successful oAuth
Hi there,
We are using Shopify Koa for our oAuth Shopify process. Thank you all of you who work on it. Appreciated.
Here is an issue we have: If your session expires during using the app and you click e.g the /producs page you get redirected to Shopify, then the /auth/callback is invoked and in my afterAuth() function we call ctx.redirect('/'). We want the user to be redirected to the original page requested (/products). However it seems that this information is lost during the oAuth. Is it possible to fix that?
P.S I hope you guys will be able to add the Shopify session tokens auth mechanism soon. We want to switch because of our Safari users and the cookies problems they have
Cheers!
You should be able to implement this in your app. Before you start authentication, save the current path in your session, then in your afterAuth callback, check the session for your return_to value and redirect to that instead.
I'm struggling with this right now.
There's no way for apps to know whether the user will be redirected to /auth without doing the checks in verifyRequest themselves.
Perhaps, a custom function as an argument to verifyRequest is an option? That gets called before the user is redirected to /auth?
E.g.
app.use(
verifyRequest({
// path to redirect to if verification fails
// defaults to '/auth'
authRoute: '/foo/auth',
// path to redirect to if verification fails and there is no shop on the query
// defaults to '/auth'
fallbackRoute: '/install',
// function that gets called before the user is redirected to authRoute / fallbackRoute
authHook: () => {
// Save the return path ctx.session.returnPath = JSON.stringify({path: ctx.path, shop: ctx.request.query.shop})
},
}),
);
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.