Adjust Auth Callback URL for self-hosted instances (#167)

* Adjust URL for local development during auth callback covering more scenarios
* Fix typechecking issues
This commit is contained in:
Giancarlo Buomprisco
2025-02-18 09:57:56 +07:00
committed by GitHub
parent 9a503412e5
commit 0478a6428d
3 changed files with 24 additions and 8 deletions

View File

@@ -73,7 +73,7 @@ function DeleteAccountForm() {
const form = useForm({
resolver: zodResolver(DeletePersonalAccountSchema),
defaultValues: {
confirmation: '',
confirmation: '' as 'DELETE'
},
});

View File

@@ -151,7 +151,7 @@ function DeleteTeamConfirmationForm({
}),
),
defaultValues: {
confirm: '',
name: ''
},
});
@@ -260,7 +260,7 @@ function LeaveTeamContainer(props: {
}),
),
defaultValues: {
confirmation: '',
confirmation: '' as 'LEAVE'
},
});

View File

@@ -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({