Files
windmill/frontend/src/lib/cookies.ts
Ruben Fiszel 0423eeedbe handle better public domain for apps (#7136)
* cookelogin

* cookelogin

* all

* all

* fix

* all

* all

* update back

* all

* all

* cookelogin

* cookelogin

* Update frontend/src/lib/components/apps/editor/PublicApp.svelte

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* Update frontend/src/lib/components/apps/editor/PublicApp.svelte

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* all

* all

---------

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
2025-11-14 10:14:32 +00:00

29 lines
984 B
TypeScript

/**
* Reads the value of a cookie by name.
* @param {string} name - The name of the cookie to retrieve.
* @returns {string | undefined} The cookie value, or undefined if not found.
*/
export function getCookie(name: string): string | undefined {
const match = document.cookie.match(
new RegExp('(?:^|; )' + name.replace(/([.$?*|{}()\[\]\\\/\+^])/g, '\\$1') + '=([^;]*)')
)
return match ? decodeURIComponent(match[1]) : undefined
}
// this only check the last 2 segments to work for popup on shared top-domain
export function sameTopDomainOrigin(origin: string | null, desktopOrigin: string): boolean {
if (origin == null) {
return false
}
const getLastTwoSegments = (url: string) => {
const parts = url.split('.');
return parts.length >= 2 ? parts.slice(-2).join('.') : url;
};
if (origin.includes('.') && desktopOrigin.includes('.')) {
return getLastTwoSegments(origin) === getLastTwoSegments(desktopOrigin);
} else {
return origin === desktopOrigin;
}
}