Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eighty-pens-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Fix a bug where client_uat domain detection would not handle hostnames with a single part. This impacts locally defined custom hostnames used as aliases.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ describe('getCookieDomain', () => {
}
});

it('handles custom hosts defined locally', () => {
expect(getCookieDomain('bryce-local')).toBe('bryce-local');
});

it('returns undefined if the domain could not be determined', () => {
const handler: CookieHandler = {
get: jest.fn().mockReturnValue(undefined),
Expand Down
5 changes: 5 additions & 0 deletions packages/clerk-js/src/utils/cookies/getCookieDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export function getCookieDomain(hostname = window.location.hostname, cookieHandl

const hostnameParts = hostname.split('.');

// Account for custom hosts defined locally, e.g. 127.0.0.1 -> local-app
if (hostnameParts.length === 1) {
return hostname;
}

// we know for sure that the first entry is definitely a TLD, skip it
for (let i = hostnameParts.length - 2; i >= 0; i--) {
const eTLD = hostnameParts.slice(i).join('.');
Expand Down