From ca64d393a6b1415d3eab070e5955b5bd11a54115 Mon Sep 17 00:00:00 2001 From: zeelrupapara Date: Fri, 31 May 2024 15:42:43 +0530 Subject: [PATCH] feat: top level domain set in the cookie --- .../utils/__tests__/auth-route-builder.spec.ts | 12 ++++++++++++ .../src/core/passport/utils/auth-routes-builder.ts | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/packages/medusa-plugin-auth/src/core/passport/utils/__tests__/auth-route-builder.spec.ts b/packages/medusa-plugin-auth/src/core/passport/utils/__tests__/auth-route-builder.spec.ts index 3cb3774..3e00986 100644 --- a/packages/medusa-plugin-auth/src/core/passport/utils/__tests__/auth-route-builder.spec.ts +++ b/packages/medusa-plugin-auth/src/core/passport/utils/__tests__/auth-route-builder.spec.ts @@ -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'); }); }); diff --git a/packages/medusa-plugin-auth/src/core/passport/utils/auth-routes-builder.ts b/packages/medusa-plugin-auth/src/core/passport/utils/auth-routes-builder.ts index 808cbc8..c490d38 100644 --- a/packages/medusa-plugin-auth/src/core/passport/utils/auth-routes-builder.ts +++ b/packages/medusa-plugin-auth/src/core/passport/utils/auth-routes-builder.ts @@ -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; };