Skip to content

Commit e8c7cd8

Browse files
committed
#282 remove cookie automatically
1 parent 98c0340 commit e8c7cd8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/src/authentication.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export async function signRequest(
7878
}
7979

8080
const ONE_DAY = 24 * 60 * 60 * 1000;
81+
const COOKIE_NAME_AUTH = 'atomic_session';
8182

8283
const setCookieExpires = (
8384
name: string,
@@ -97,10 +98,14 @@ const setCookieExpires = (
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) => {
99100
createAuthentication(store.getServerUrl(), agent).then(auth => {
100-
setCookieExpires('atomic_session', btoa(JSON.stringify(auth)), store);
101+
setCookieExpires(COOKIE_NAME_AUTH, btoa(JSON.stringify(auth)), store);
101102
});
102103
};
103104

105+
export const removeCookieAuthentication = () => {
106+
document.cookie = `${COOKIE_NAME_AUTH}=;Max-Age=-99999999`;
107+
};
108+
104109
/** Returns false if the auth cookie is not set / expired */
105110
export const checkAuthenticationCookie = (): boolean => {
106111
const matches = document.cookie.match(

lib/src/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
parseCommit,
1010
parseJsonADArray,
1111
parseJsonADResource,
12+
removeCookieAuthentication,
1213
Resource,
1314
serializeDeterministically,
1415
setCookieAuthentication,
@@ -67,6 +68,8 @@ export async function fetchResource(
6768
} else {
6869
await signRequest(subject, agent, requestHeaders);
6970
}
71+
} else {
72+
removeCookieAuthentication();
7073
}
7174

7275
let url = subject;

0 commit comments

Comments
 (0)