Skip to content

Commit d9d1b7f

Browse files
committed
chore(clerk-js): Add JSDoc for auth services and cookies
1 parent d911c3f commit d9d1b7f

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

packages/clerk-js/src/core/auth/AuthCookieService.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,25 @@ import type { DevBrowser } from './devBrowser';
1313
import { createDevBrowser } from './devBrowser';
1414
import { SessionCookiePoller } from './SessionCookiePoller';
1515

16-
// TODO: make AuthCookieService singleton since it handles updating cookies using a poller
16+
// TODO(@dimkl): make AuthCookieService singleton since it handles updating cookies using a poller
1717
// and we need to avoid updating them concurrently.
18+
/**
19+
* The AuthCookieService class is a service responsible to handle
20+
* all operations and helpers required in a standard browser context
21+
* based on the cookies to remove the dependency between cookies
22+
* and auth from the Clerk instance.
23+
* This service is responsible to:
24+
* - refresh the session cookie using a poller
25+
* - refresh the session cookie on tab visibility change
26+
* - update the related cookies listening to the `token:update` event
27+
* - initialize auth related cookies for development instances (eg __client_uat, __clerk_db_jwt)
28+
* - cookie setup for production / development instances
29+
* It also provides the following helpers:
30+
* - isSignedOut(): check if the current user is signed-out using cookies
31+
* - urlWithAuth(): decorates url with auth related info (eg dev browser jwt)
32+
* - handleUnauthenticatedDevBrowser(): resets dev browser in case of invalid dev browser
33+
* - setEnvironment(): update cookies (eg client_uat) related to environment
34+
*/
1835
export class AuthCookieService {
1936
private environment: EnvironmentResource | undefined;
2037
private poller: SessionCookiePoller | null = null;
@@ -40,6 +57,7 @@ export class AuthCookieService {
4057
});
4158
}
4259

60+
// TODO(@dimkl): Replace this method call with an event listener to decouple Clerk with setEnvironment
4361
public setEnvironment(environment: EnvironmentResource) {
4462
this.environment = environment;
4563
this.setClientUatCookieForDevelopmentInstances();

packages/clerk-js/src/core/auth/cookies/clientUat.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export type ClientUatCookieHandler = {
1212
get: () => number;
1313
};
1414

15+
/**
16+
* Create a long-lived JS cookie to store the client last updated_at timestamp
17+
* for development instances (for production instance is set by FAPI).
18+
* The cookie is used as hint from the Clerk Backend packages to identify
19+
* if the user is authenticated or not.
20+
*/
1521
export const createClientUatCookie = (): ClientUatCookieHandler => {
1622
const clientUatCookie = createCookieHandler(CLIENT_UAT_COOKIE_NAME);
1723

packages/clerk-js/src/core/auth/cookies/devBrowser.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ export type DevBrowserCookieHandler = {
1010
remove: () => void;
1111
};
1212

13+
/**
14+
* Create a long-lived JS cookie to store the dev browser token
15+
* ONLY for development instances.
16+
* The cookie is used to authenticate FAPI requests and pass
17+
* authentication from AP to the app.
18+
*/
1319
export const createDevBrowserCookie = (): DevBrowserCookieHandler => {
1420
const devBrowserCookie = createCookieHandler(DEV_BROWSER_JWT_KEY);
1521

packages/clerk-js/src/core/auth/cookies/session.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ export type SessionCookieHandler = {
1010
remove: () => void;
1111
};
1212

13+
/**
14+
* Create a short-lived JS cookie to store the current user JWT.
15+
* The cookie is used by the Clerk backend SDKs to identify
16+
* the authenticated user.
17+
*/
1318
export const createSessionCookie = (): SessionCookieHandler => {
14-
/**
15-
*
16-
* This is a short-lived JS cookie used to store the current user JWT.
17-
*
18-
*/
1919
const sessionCookie = createCookieHandler(SESSION_COOKIE_NAME);
2020

2121
const remove = () => sessionCookie.remove();

0 commit comments

Comments
 (0)