Skip to content

Commit 7a239f6

Browse files
replace deprecated maxAge property in lru cache to fix warning
1 parent ec5115d commit 7a239f6

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simple-koa-shopify-auth",
3-
"version": "2.1.15",
3+
"version": "2.1.16",
44
"description": "A better, simplified version of the (no longer supported) @Shopify/koa-shopify-auth middleware library. It removes the use of cookies for sessions (which greatly smooths the auth process), replaces a deprecated API call, and supports v2 of the official @shopify/shopify-api package.",
55
"author": "TheSecurityDev",
66
"license": "MIT",

src/top-level-oauth-redirect.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export const TOP_LEVEL_OAUTH_COOKIE_NAME = "shopifyTopLevelOAuth"; // If this is
88
const RELATIVE_APP_BRIDGE_PATH = "../app-bridge/[email protected]";
99
const APP_BRIDGE_FILE_PATH = resolvePath(__dirname, RELATIVE_APP_BRIDGE_PATH); // Get global path from relative path to this module
1010

11+
// NOTE: Top level means we're in the top level window, not embedded in an iframe
12+
1113
export function shouldPerformTopLevelOAuth({ cookies }: Context) {
1214
return Boolean(cookies.get(TOP_LEVEL_OAUTH_COOKIE_NAME));
1315
}
@@ -46,6 +48,7 @@ export async function startTopLevelOauthRedirect(ctx: Context, apiKey: string, p
4648
);
4749
}
4850

51+
// TODO: We should refactor this ugly mess and remove the parts we don't need anymore.
4952
async function getTopLevelRedirectScript(host: string, redirectTo: string, apiKey: string) {
5053
let shopName = "";
5154
try {

src/verify-request.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@ async function clearSession(ctx: Context, accessMode = defaultOptions.accessMode
121121
}
122122
}
123123

124+
// Cache the results of the verify access token request
124125
const VERIFY_TOKEN_REQUEST_CACHE = new LRUCache({
125126
max: 1000,
126-
maxAge: 1000 * 60 * 60, // 1 hour
127-
}); // Cache the results of the verify access token request
127+
ttl: 1000 * 60 * 60, // 1 hour
128+
// Don't use the fetchMethod, because we want to catch errors and I think it might handle the error without throwing
129+
});
128130

129131
async function checkSessionOnShopifyAPI(session: Session) {
130132
const { shop, accessToken } = session;
@@ -134,7 +136,7 @@ async function checkSessionOnShopifyAPI(session: Session) {
134136
const cacheKey = `${shop}:${accessToken}`;
135137
if (!VERIFY_TOKEN_REQUEST_CACHE.get(cacheKey)) {
136138
// We haven't verified this access token yet, so make a request to make sure the token is valid on Shopify's end.
137-
// If it's not valid, we'll get a 401 and have to re-authorize.
139+
// If it's not valid, it will throw a 401 error and have to re-authorize.
138140
const client = new Shopify.Clients.Rest(shop, accessToken);
139141
await client.get({ path: "shop" }); // Fetch /shop route on Shopify to verify the token is valid
140142
VERIFY_TOKEN_REQUEST_CACHE.set(cacheKey, true); // Cache the result

0 commit comments

Comments
 (0)