[CORL-1148] Chrome Local Storage Issues (#2994)

* fix: moved storage access inside try/catch

* chore: version bump
This commit is contained in:
Wyatt Johnson
2020-06-22 16:29:06 +00:00
committed by GitHub
parent 0fa27ae41b
commit 9022532525
3 changed files with 6 additions and 11 deletions
+2 -2
View File
@@ -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": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@coralproject/talk",
"version": "6.2.1",
"version": "6.2.2",
"author": "The Coral Project",
"homepage": "https://coralproject.net/",
"sideEffects": [
+3 -8
View File
@@ -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