mirror of
https://github.com/documenso/documenso.git
synced 2026-08-15 02:53:32 +10:00
18 lines
507 B
TypeScript
18 lines
507 B
TypeScript
/**
|
|
* Read a cookie value from `document.cookie`.
|
|
*
|
|
* Client-side counterpart of `extractCookieFromHeaders`. Only works for cookies that
|
|
* are not `HttpOnly`, such as the preferred team URL cookie.
|
|
*/
|
|
export const extractCookieFromDocument = (cookieName: string): string | null => {
|
|
const cookiePairs = document.cookie.split(';');
|
|
|
|
const cookie = cookiePairs.find((pair) => pair.trim().startsWith(`${cookieName}=`));
|
|
|
|
if (!cookie) {
|
|
return null;
|
|
}
|
|
|
|
return cookie.split('=')[1].trim();
|
|
};
|