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

Commit

Permalink
fixed missing localStorage in nodejs
Browse files Browse the repository at this point in the history
  • Loading branch information
poef committed Feb 18, 2024
1 parent e090862 commit 9a7f153
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/mw/oauth2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@ 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 = {
get: () => stateMap.get('metro/state'),
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',
Expand Down

0 comments on commit 9a7f153

Please sign in to comment.