Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
chore(baseConfig): get token stored in old format over to new one
Browse files Browse the repository at this point in the history
  • Loading branch information
doktordirk committed Apr 12, 2016
1 parent 90e621f commit 4d0f8a9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ export class Authentication {
this.payload = null;
this.exp = null;
this.hasDataStored = false;

// get token stored in previous format over
const oldStorageKey = config.tokenPrefix
? config.tokenPrefix + '_' + config.tokenName
: this.tokenName;
const oldToken = storage.get(oldStorageKey);

if (oldToken) {
let fakeOldResponse = {};
fakeOldResponse[config.accessTokenProp] = oldToken;
this.responseObject = fakeOldResponse;
storage.remove(oldStorageKey);
}
}


Expand Down
6 changes: 3 additions & 3 deletions src/baseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ export class BaseConfig {

set tokenPrefix(tokenPrefix) {
console.warn('BaseConfig.tokenPrefix is obsolete. Use BaseConfig.storageKey instead.');
this._tokenPrefix = this.storageKey;
return this.storageKey;
this._tokenPrefix = tokenPrefix;
return tokenPrefix;
}
get tokenPrefix() {
return this._tokenPrefix;
return this._tokenPrefix || 'aurelia';
}
}
19 changes: 19 additions & 0 deletions test/authentication.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ const tokenFuture = {


describe('Authentication', () => {
describe('.constructor()', () => {
const container = new Container();

afterEach(() => {
window.localStorage.removeItem('aurelia_authentication');
container.get(Authentication).deleteData();
});

it('should return old accessToken and delete in storage', () => {
window.localStorage.setItem('aurelia_token', 'old one');

const authentication = container.get(Authentication);
const token = authentication.getAccessToken();

expect(token).toBe('old one');
});
});


describe('.responseObject', () => {
const container = new Container();
const authentication = container.get(Authentication);
Expand Down

0 comments on commit 4d0f8a9

Please sign in to comment.