From 0478a6428d7e8d0be453fd5da06477ae3e322236 Mon Sep 17 00:00:00 2001 From: Giancarlo Buomprisco Date: Tue, 18 Feb 2025 09:57:56 +0700 Subject: [PATCH] Adjust Auth Callback URL for self-hosted instances (#167) * Adjust URL for local development during auth callback covering more scenarios * Fix typechecking issues --- .../account-danger-zone.tsx | 2 +- .../settings/team-account-danger-zone.tsx | 4 +-- .../supabase/src/auth-callback.service.ts | 26 +++++++++++++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/features/accounts/src/components/personal-account-settings/account-danger-zone.tsx b/packages/features/accounts/src/components/personal-account-settings/account-danger-zone.tsx index 3c5177a4e..36be0fcd8 100644 --- a/packages/features/accounts/src/components/personal-account-settings/account-danger-zone.tsx +++ b/packages/features/accounts/src/components/personal-account-settings/account-danger-zone.tsx @@ -73,7 +73,7 @@ function DeleteAccountForm() { const form = useForm({ resolver: zodResolver(DeletePersonalAccountSchema), defaultValues: { - confirmation: '', + confirmation: '' as 'DELETE' }, }); diff --git a/packages/features/team-accounts/src/components/settings/team-account-danger-zone.tsx b/packages/features/team-accounts/src/components/settings/team-account-danger-zone.tsx index e6dc57a22..ad36ae452 100644 --- a/packages/features/team-accounts/src/components/settings/team-account-danger-zone.tsx +++ b/packages/features/team-accounts/src/components/settings/team-account-danger-zone.tsx @@ -151,7 +151,7 @@ function DeleteTeamConfirmationForm({ }), ), defaultValues: { - confirm: '', + name: '' }, }); @@ -260,7 +260,7 @@ function LeaveTeamContainer(props: { }), ), defaultValues: { - confirmation: '', + confirmation: '' as 'LEAVE' }, }); diff --git a/packages/supabase/src/auth-callback.service.ts b/packages/supabase/src/auth-callback.service.ts index a98f3b3c6..1190bc247 100644 --- a/packages/supabase/src/auth-callback.service.ts +++ b/packages/supabase/src/auth-callback.service.ts @@ -42,11 +42,8 @@ class AuthCallbackService { const host = request.headers.get('host'); - // set the host to the request host since outside of Vercel it gets set as "localhost" - if (url.host.includes('localhost:') && !host?.includes('localhost')) { - url.host = host as string; - url.port = ''; - } + // set the host to the request host since outside of Vercel it gets set as "localhost" or "0.0.0.0" + this.adjustUrlHostForLocalDevelopment(url, host); url.pathname = params.redirectPath; @@ -213,6 +210,25 @@ class AuthCallbackService { nextPath: nextUrl, }; } + + private adjustUrlHostForLocalDevelopment(url: URL, host: string | null) { + if (this.isLocalhost(url.host) && !this.isLocalhost(host)) { + url.host = host as string; + url.port = ''; + } + } + + private isLocalhost(host: string | null) { + if (!host) { + return false; + } + + return ( + host.includes('localhost:') || + host.includes('0.0.0.0:') || + host.includes('127.0.0.1:') + ); + } } function onError({