From 9a7f153295408a8d9a2822fbd735b55e50ca63a5 Mon Sep 17 00:00:00 2001 From: Auke van Slooten Date: Sun, 18 Feb 2024 16:59:47 +0100 Subject: [PATCH] fixed missing localStorage in nodejs --- src/mw/oauth2.mjs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mw/oauth2.mjs b/src/mw/oauth2.mjs index 893926a..244e827 100644 --- a/src/mw/oauth2.mjs +++ b/src/mw/oauth2.mjs @@ -4,13 +4,18 @@ import jsonmw from './json.mjs' export default function oauth2mw(options) { - let localState + let localState, localTokens if (typeof localStorage !== 'undefined') { localState = { get: () => localStorage.getItem('metro/state'), has: () => localStorage.getItem('metro/state'), set: (value) => localStorage.setItem('metro/state', value) } + localTokens = { + get: (name) => localStorage.getItem(name), + set: (name, value) => localStorage.setItem(name, value), + has: (name) => localStorage.hasItem(name) + } } else { let stateMap = new Map() localState = { @@ -18,10 +23,11 @@ export default function oauth2mw(options) { has: () => stateMap.get('metro/state'), set: (value) => stateMap.set('metro/state', value) } + localTokens = new Map() } const oauth2 = { - tokens: localStorage, + tokens: localTokens, state: localState, endpoints: { authorize: '/authorize',