Skip to content

Commit 5ea933f

Browse files
committed
#282 cookie clean up
1 parent 2ce05f7 commit 5ea933f

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/src/authentication.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
getTimestampNow,
44
HeadersObject,
55
signToBase64,
6+
Store,
67
} from './index.js';
78

89
/** Returns a JSON-AD resource of an Authentication */
@@ -91,10 +92,13 @@ const setCookieExpires = (
9192
document.cookie = cookieString;
9293
};
9394

95+
const COOKIE_NAME_AUTH = 'atomic_session';
96+
9497
/** Sets a cookie for the current Agent, signing the Authentication. It expires after some default time. */
95-
export const setCookieAuthentication = (serverUrl: string, agent: Agent) => {
96-
createAuthentication(serverUrl, agent).then(auth => {
97-
setCookieExpires('atomic_session', btoa(JSON.stringify(auth)), serverUrl);
98+
export const setCookieAuthentication = (store: Store, agent: Agent) => {
99+
const serverURL = store.getServerUrl();
100+
createAuthentication(serverURL, agent).then(auth => {
101+
setCookieExpires(COOKIE_NAME_AUTH, btoa(JSON.stringify(auth)), serverURL);
98102
});
99103
};
100104

lib/src/store.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { setCookieAuthentication } from './authentication.js';
1+
import {
2+
removeCookieAuthentication,
3+
setCookieAuthentication,
4+
} from './authentication.js';
25
import { EventManager } from './EventManager.js';
36
import {
47
Agent,
@@ -504,6 +507,8 @@ export class Store {
504507
this.fetchResourceFromServer(r.getSubject());
505508
}
506509
});
510+
} else {
511+
removeCookieAuthentication();
507512
}
508513

509514
this.eventManager.emit(StoreEvents.AgentChanged, agent);

0 commit comments

Comments
 (0)