Skip to content

Commit

Permalink
#282 cookie clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Feb 4, 2023
1 parent 8616053 commit f71c942
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/src/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
HeadersObject,
properties,
signToBase64,
Store,
} from './index.js';

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

/** Sets a cookie for the current Agent, signing the Authentication. It expires after some default time. */
export const setCookieAuthentication = (store: Store, agent: Agent) => {
createAuthentication(store.getServerUrl(), agent).then(auth => {
setCookieExpires(COOKIE_NAME_AUTH, btoa(JSON.stringify(auth)), store);
const serverURL = store.getServerUrl();
createAuthentication(serverURL, agent).then(auth => {
setCookieExpires(COOKIE_NAME_AUTH, btoa(JSON.stringify(auth)), serverURL);
});
};

Expand Down
7 changes: 6 additions & 1 deletion lib/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { setCookieAuthentication } from './authentication.js';
import {
removeCookieAuthentication,
setCookieAuthentication,
} from './authentication.js';
import { EventManager } from './EventManager.js';
import {
Agent,
Expand Down Expand Up @@ -488,6 +491,8 @@ export class Store {
this.fetchResourceFromServer(r.getSubject());
}
});
} else {
removeCookieAuthentication();
}

this.eventManager.emit(StoreEvents.AgentChanged, agent);
Expand Down

0 comments on commit f71c942

Please sign in to comment.