From c3feffba7b7832fc4551b82cb5ed8f84bed86985 Mon Sep 17 00:00:00 2001 From: Federico Date: Thu, 8 Oct 2026 15:20:36 -0300 Subject: [PATCH] Redirigir las URLs viejas de Firebase a app.winbit.com.ar --- src/main.jsx | 36 ++++++++++++++---------- src/utils/legacyHostRedirect.js | 9 ++++++ src/utils/legacyHostRedirect.test.js | 42 ++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 src/utils/legacyHostRedirect.js create mode 100644 src/utils/legacyHostRedirect.test.js diff --git a/src/main.jsx b/src/main.jsx index 3cbbb29..30681bd 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -6,6 +6,12 @@ import './i18n'; import { QueryClientProvider } from '@tanstack/react-query'; import { queryClient } from './lib/queryClient'; import './index.css'; +import { getLegacyRedirectUrl } from './utils/legacyHostRedirect'; + +const legacyRedirectUrl = getLegacyRedirectUrl(globalThis?.location); +if (legacyRedirectUrl) { + globalThis.location.replace(legacyRedirectUrl); +} // Show [DEV] in the browser tab when running locally. const isLocalHost = ['localhost', '127.0.0.1', '0.0.0.0'].includes(globalThis?.location?.hostname); @@ -27,17 +33,19 @@ if (import.meta.env.DEV && typeof navigator !== 'undefined' && 'serviceWorker' i } } -ReactDOM.createRoot(document.getElementById('root')).render( - - - - - - - , -); +if (!legacyRedirectUrl) { + ReactDOM.createRoot(document.getElementById('root')).render( + + + + + + + , + ); +} diff --git a/src/utils/legacyHostRedirect.js b/src/utils/legacyHostRedirect.js new file mode 100644 index 0000000..9d97ee2 --- /dev/null +++ b/src/utils/legacyHostRedirect.js @@ -0,0 +1,9 @@ +const LEGACY_HOSTS = ['winbit-6579c.web.app', 'winbit-6579c.firebaseapp.com']; +const CURRENT_ORIGIN = 'https://app.winbit.com.ar'; + +// `/__/` is reserved by Firebase Hosting (Google sign-in handler); never redirect it. +export const getLegacyRedirectUrl = ({ hostname, pathname = '/', search = '', hash = '' } = {}) => { + if (!LEGACY_HOSTS.includes(hostname)) return null; + if (pathname.startsWith('/__/')) return null; + return `${CURRENT_ORIGIN}${pathname}${search}${hash}`; +}; diff --git a/src/utils/legacyHostRedirect.test.js b/src/utils/legacyHostRedirect.test.js new file mode 100644 index 0000000..ce0b8b3 --- /dev/null +++ b/src/utils/legacyHostRedirect.test.js @@ -0,0 +1,42 @@ +import { describe, it, expect } from 'vitest'; +import { getLegacyRedirectUrl } from './legacyHostRedirect'; + +describe('getLegacyRedirectUrl', () => { + it('redirects the legacy web.app host to the current domain', () => { + expect(getLegacyRedirectUrl({ hostname: 'winbit-6579c.web.app', pathname: '/' })).toBe( + 'https://app.winbit.com.ar/', + ); + }); + + it('redirects the legacy firebaseapp.com host', () => { + expect( + getLegacyRedirectUrl({ hostname: 'winbit-6579c.firebaseapp.com', pathname: '/login' }), + ).toBe('https://app.winbit.com.ar/login'); + }); + + it('preserves path, query string and hash', () => { + expect( + getLegacyRedirectUrl({ + hostname: 'winbit-6579c.web.app', + pathname: '/history', + search: '?tab=2', + hash: '#top', + }), + ).toBe('https://app.winbit.com.ar/history?tab=2#top'); + }); + + it('never redirects the Firebase reserved /__/ paths', () => { + expect( + getLegacyRedirectUrl({ + hostname: 'winbit-6579c.firebaseapp.com', + pathname: '/__/auth/handler', + }), + ).toBeNull(); + }); + + it('does not redirect the current domain or local hosts', () => { + expect(getLegacyRedirectUrl({ hostname: 'app.winbit.com.ar', pathname: '/' })).toBeNull(); + expect(getLegacyRedirectUrl({ hostname: 'localhost', pathname: '/' })).toBeNull(); + expect(getLegacyRedirectUrl()).toBeNull(); + }); +});