Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
🐛 fix auth issue with invalid accesstoken
Browse files Browse the repository at this point in the history
  • Loading branch information
Katie Davis committed Aug 13, 2019
1 parent 23e4e4d commit d57bc8c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/koa-shopify-auth/src/verify-request/verify-request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Context} from 'koa';

import {NextFunction} from '../types';
import {TEST_COOKIE_NAME, TOP_LEVEL_OAUTH_COOKIE_NAME} from '../index';

Expand All @@ -23,6 +22,20 @@ export default function verifyRequest({

if (session && session.accessToken) {
ctx.cookies.set(TOP_LEVEL_OAUTH_COOKIE_NAME);
// we need to check if the accessToken is valid.
const response = await fetch(`https://${shop}/admin/metafields.json`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Shopify-Access-Token': session.accessToken,
},
});

if (response.status === 401) {
ctx.redirect(`${authRoute}?shop=${shop}`);
return;
}

await next();
return;
}
Expand Down

0 comments on commit d57bc8c

Please sign in to comment.