Skip to content

Commit

Permalink
feat: top level domain set in the cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
zeelrupapara committed May 31, 2024
1 parent d0c1047 commit ca64d39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,17 @@ describe('auth route builder', () => {
url = 'http://google.com';
domain = extractDomain(url);
expect(domain).toBe('google.com');

url = 'http://auth.google.com/';
domain = extractDomain(url);
expect(domain).toBe('google.com');

url = 'https://auth.google.com/';
domain = extractDomain(url);
expect(domain).toBe('google.com');

url = 'https://www.auth.google.com/';
domain = extractDomain(url);
expect(domain).toBe('google.com');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ type PassportCallbackAuthenticateMiddlewareOptions = {

export const extractDomain = (url) => {
const domain = url.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)/im)[1];
const mainDomain = domain.split('.');
if (mainDomain.length > 2) {
// Return the domain and top-level domain (TLD)
return mainDomain.slice(-2).join('.');
}
return domain;
};

Expand Down

0 comments on commit ca64d39

Please sign in to comment.