Skip to content

Commit

Permalink
Remove local storage. (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-lee committed Oct 31, 2023
1 parent 4338088 commit 12a7c28
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 324 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cspace-client",
"version": "2.0.0-rc.1",
"version": "2.0.0-rc.2",
"description": "CollectionSpace client for browsers and Node.js",
"author": "Ray Lee <ray.lee@lyrasis.org>",
"license": "ECL-2.0",
Expand Down
51 changes: 0 additions & 51 deletions src/localStorageTokenStore.js

This file was deleted.

31 changes: 0 additions & 31 deletions src/memoryTokenStore.js

This file was deleted.

12 changes: 0 additions & 12 deletions src/session.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import cspace from 'cspace-api';
import urljoin from 'url-join';
import tokenStore from './tokenStore';
import { parseJwt } from './tokenHelpers';

const defaultSessionConfig = {
Expand All @@ -15,17 +14,9 @@ export default function session(sessionConfig) {
...sessionConfig,
};

const authStore = tokenStore(config.clientId, config.url);

let authRequestPending = null;
let auth = {};

if (!config.authCode) {
// The auth code for this session wasn't specified. Use the stored auth, if any.

auth = authStore.fetch() || {};
}

const cs = cspace({
url: urljoin(config.url, 'cspace-services'),
});
Expand Down Expand Up @@ -57,8 +48,6 @@ export default function session(sessionConfig) {
refreshToken,
};

authStore.store(auth);

// We have tokens, so the authoriztion code, code verifier, and client secret can be discarded.

delete config.authCode;
Expand Down Expand Up @@ -105,7 +94,6 @@ export default function session(sessionConfig) {
return serviceLogoutPromise
.finally(() => {
auth = {};
authStore.clear();

resolve({});
});
Expand Down
17 changes: 0 additions & 17 deletions src/tokenHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@

export const storageKey = 'cspace-client';

export const isLocalStorageAvailable = () => {
// Taken from
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API

try {
const storage = window.localStorage;
const x = '__storage_test__';

storage.setItem(x, x);
storage.removeItem(x);

return true;
} catch (error) {
return false;
}
};

const base64Decode = (encoded) => {
if (typeof window !== 'undefined') {
// We're in a browser.
Expand Down
9 changes: 0 additions & 9 deletions src/tokenStore.js

This file was deleted.

17 changes: 17 additions & 0 deletions test/integration/crud.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import client from '../../src/client';

const { expect } = chai;

chai.use(chaiAsPromised);
chai.should();

Expand Down Expand Up @@ -59,6 +61,11 @@ describe.skip(`crud operations on ${clientConfig.url}`, function suite() {

let objectCsid = '';

it('reports null logged in username before logging in', () => {
expect(adminSession.username()).to.equal(null);
expect(readerSession.username()).to.equal(null);
});

it('cannot list records as admin before logging in', () => (
adminSession.read('collectionobjects').should.eventually
.be.rejected
Expand Down Expand Up @@ -93,6 +100,11 @@ describe.skip(`crud operations on ${clientConfig.url}`, function suite() {
})
));

it('reports the logged in username', () => {
adminSession.username().should.equal('admin@core.collectionspace.org');
readerSession.username().should.equal('reader@core.collectionspace.org');
});

it('can create an object record as admin', function test() {
if (!adminLoggedIn) {
this.skip();
Expand Down Expand Up @@ -333,6 +345,11 @@ describe.skip(`crud operations on ${clientConfig.url}`, function suite() {
.and.be.an('object')
));

it('reports null logged in username after logging out', () => {
expect(adminSession.username()).to.equal(null);
expect(readerSession.username()).to.equal(null);
});

it('can log out multiple times', () => (
readerSession.logout().should.eventually
.be.fulfilled
Expand Down
79 changes: 0 additions & 79 deletions test/specs/localStorageTokenStore.spec.js

This file was deleted.

73 changes: 0 additions & 73 deletions test/specs/memoryTokenStore.spec.js

This file was deleted.

0 comments on commit 12a7c28

Please sign in to comment.