Compare commits

...
Author SHA1 Message Date
Wyatt Johnson 9022532525 [CORL-1148] Chrome Local Storage Issues (#2994)
* fix: moved storage access inside try/catch

* chore: version bump
2020-06-22 16:29:06 +00:00
Wyatt Johnson 0fa27ae41b chore: bump version 2020-06-08 17:30:39 -06:00
Wyatt Johnson 0065875f12 fix: ensure access token is null not undefined (#2981) 2020-06-08 23:28:07 +00:00
7 changed files with 20 additions and 14 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@coralproject/talk",
"version": "6.2.0",
"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.0",
"version": "6.2.2",
"author": "The Coral Project",
"homepage": "https://coralproject.net/",
"sideEffects": [
@@ -5,6 +5,7 @@ exports[`get access token from url 1`] = `
\\"__id\\": \\"client:root.local\\",
\\"__typename\\": \\"Local\\",
\\"accessToken\\": \\"eyJraWQiOiI5NmM4MDY2YS1kOTg3LTQyODItODNmOS1kYTUxNjc5N2Y5ZmMiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIzMWIyNjU5MS00ZTlhLTQzODgtYTdmZi1lMWJkYzVkOTdjY2UifQ==.\\",
\\"accessTokenExp\\": null,
\\"accessTokenJTI\\": \\"31b26591-4e9a-4388-a7ff-e1bdc5d97cce\\",
\\"redirectPath\\": null,
\\"authView\\": \\"SIGN_IN\\",
@@ -24,6 +25,9 @@ exports[`init local state 1`] = `
\\"client:root.local\\": {
\\"__id\\": \\"client:root.local\\",
\\"__typename\\": \\"Local\\",
\\"accessToken\\": null,
\\"accessTokenExp\\": null,
\\"accessTokenJTI\\": null,
\\"redirectPath\\": null,
\\"authView\\": \\"SIGN_IN\\",
\\"authError\\": null
@@ -5,6 +5,7 @@ exports[`get access token from url 1`] = `
\\"__id\\": \\"client:root.local\\",
\\"__typename\\": \\"Local\\",
\\"accessToken\\": \\"eyJraWQiOiI5NmM4MDY2YS1kOTg3LTQyODItODNmOS1kYTUxNjc5N2Y5ZmMiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIzMWIyNjU5MS00ZTlhLTQzODgtYTdmZi1lMWJkYzVkOTdjY2UifQ==.\\",
\\"accessTokenExp\\": null,
\\"accessTokenJTI\\": \\"31b26591-4e9a-4388-a7ff-e1bdc5d97cce\\",
\\"view\\": \\"SIGN_IN\\",
\\"error\\": null
@@ -23,6 +24,9 @@ exports[`init local state 1`] = `
\\"client:root.local\\": {
\\"__id\\": \\"client:root.local\\",
\\"__typename\\": \\"Local\\",
\\"accessToken\\": null,
\\"accessTokenExp\\": null,
\\"accessTokenJTI\\": null,
\\"view\\": \\"SIGN_IN\\",
\\"error\\": null
}
+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
@@ -38,10 +38,10 @@ export function initLocalBaseState(
root.setLinkedRecord(local, "local");
// Update the access token properties.
local.setValue(auth?.accessToken, "accessToken");
local.setValue(auth?.accessToken || null, "accessToken");
// Update the claims.
local.setValue(auth?.claims.exp, "accessTokenExp");
local.setValue(auth?.claims.jti, "accessTokenJTI");
local.setValue(auth?.claims.exp || null, "accessTokenExp");
local.setValue(auth?.claims.jti || null, "accessTokenJTI");
});
}
@@ -12,6 +12,9 @@ exports[`init local state 1`] = `
\\"client:root.local\\": {
\\"__id\\": \\"client:root.local\\",
\\"__typename\\": \\"Local\\",
\\"accessToken\\": null,
\\"accessTokenExp\\": null,
\\"accessTokenJTI\\": null,
\\"commentsOrderBy\\": \\"CREATED_AT_DESC\\",
\\"authPopup\\": {
\\"__ref\\": \\"client:root.local.authPopup\\"