From 9022532525c8be18f35d9e3ea1831ce94894fde7 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 22 Jun 2020 16:29:06 +0000 Subject: [PATCH] [CORL-1148] Chrome Local Storage Issues (#2994) * fix: moved storage access inside try/catch * chore: version bump --- package-lock.json | 4 ++-- package.json | 2 +- src/core/client/framework/lib/auth/auth.ts | 11 +++-------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3a6f92a29..f43b5a18b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@coralproject/talk", - "version": "6.2.1", + "version": "6.2.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -31137,7 +31137,7 @@ }, "chalk": { "version": "1.1.3", - "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "dev": true, "requires": { diff --git a/package.json b/package.json index 7356f8765..643624df2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@coralproject/talk", - "version": "6.2.1", + "version": "6.2.2", "author": "The Coral Project", "homepage": "https://coralproject.net/", "sideEffects": [ diff --git a/src/core/client/framework/lib/auth/auth.ts b/src/core/client/framework/lib/auth/auth.ts index 584250811..4cb6f3b0d 100644 --- a/src/core/client/framework/lib/auth/auth.ts +++ b/src/core/client/framework/lib/auth/auth.ts @@ -5,11 +5,6 @@ import { Claims, computeExpiresIn, parseAccessTokenClaims } from "./helpers"; */ const ACCESS_TOKEN_KEY = "coral:v1:accessToken"; -/** - * storage is the Storage used to retrieve/update/delete access tokens on. - */ -const storage = localStorage; - export interface AuthState { /** * accessToken is the access token issued by the server. @@ -46,7 +41,7 @@ function parseAccessToken(accessToken: string) { export function retrieveAccessToken() { try { // Get the access token from storage. - const accessToken = storage.getItem(ACCESS_TOKEN_KEY); + const accessToken = localStorage.getItem(ACCESS_TOKEN_KEY); if (!accessToken) { // Looks like the access token wasn't in storage. return; @@ -66,7 +61,7 @@ export function retrieveAccessToken() { export function storeAccessToken(accessToken: string) { try { // Update the access token in storage. - storage.setItem(ACCESS_TOKEN_KEY, accessToken); + localStorage.setItem(ACCESS_TOKEN_KEY, accessToken); } catch (err) { // TODO: (wyattjoh) add error reporting around this error // eslint-disable-next-line no-console @@ -79,7 +74,7 @@ export function storeAccessToken(accessToken: string) { export function deleteAccessToken() { try { - storage.removeItem(ACCESS_TOKEN_KEY); + localStorage.removeItem(ACCESS_TOKEN_KEY); } catch (err) { // TODO: (wyattjoh) add error reporting around this error // eslint-disable-next-line no-console