Skip to content

Commit c755770

Browse files
committed
#282 remove cookie automatically
1 parent 37252d2 commit c755770

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/src/authentication.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export async function signRequest(
7777
}
7878

7979
const ONE_DAY = 24 * 60 * 60 * 1000;
80+
const COOKIE_NAME_AUTH = 'atomic_session';
8081

8182
const setCookieExpires = (
8283
name: string,
@@ -94,12 +95,16 @@ const setCookieExpires = (
9495
};
9596

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

104+
export const removeCookieAuthentication = () => {
105+
document.cookie = `${COOKIE_NAME_AUTH}=;Max-Age=-99999999`;
106+
};
107+
103108
/** Returns false if the auth cookie is not set / expired */
104109
export const checkAuthenticationCookie = (): boolean => {
105110
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,9 @@ import {
99
ErrorType,
1010
JSONADParser,
1111
parseCommit,
12+
parseJsonADArray,
13+
parseJsonADResource,
14+
removeCookieAuthentication,
1215
Resource,
1316
serializeDeterministically,
1417
setCookieAuthentication,

0 commit comments

Comments
 (0)