Skip to content

Commit f71c942

Browse files
committed
#282 cookie clean up
1 parent 8616053 commit f71c942

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/src/authentication.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
HeadersObject,
66
properties,
77
signToBase64,
8+
Store,
89
} from './index.js';
910

1011
/** Returns a JSON-AD resource of an Authentication */
@@ -96,8 +97,9 @@ const setCookieExpires = (
9697

9798
/** Sets a cookie for the current Agent, signing the Authentication. It expires after some default time. */
9899
export const setCookieAuthentication = (store: Store, agent: Agent) => {
99-
createAuthentication(store.getServerUrl(), agent).then(auth => {
100-
setCookieExpires(COOKIE_NAME_AUTH, btoa(JSON.stringify(auth)), store);
100+
const serverURL = store.getServerUrl();
101+
createAuthentication(serverURL, agent).then(auth => {
102+
setCookieExpires(COOKIE_NAME_AUTH, btoa(JSON.stringify(auth)), serverURL);
101103
});
102104
};
103105

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,
@@ -488,6 +491,8 @@ export class Store {
488491
this.fetchResourceFromServer(r.getSubject());
489492
}
490493
});
494+
} else {
495+
removeCookieAuthentication();
491496
}
492497

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

0 commit comments

Comments
 (0)