WIP - BFF

This commit is contained in:
Francisco Gaona
2026-02-04 00:21:06 +01:00
parent f68321c802
commit 0e2f3dddbc
17 changed files with 645 additions and 254 deletions

View File

@@ -74,24 +74,8 @@ definePageMeta({
auth: false
})
const config = useRuntimeConfig()
const router = useRouter()
// Extract subdomain from hostname
const getSubdomain = () => {
if (!import.meta.client) return null
const hostname = window.location.hostname
const parts = hostname.split('.')
if (hostname === 'localhost' || hostname === '127.0.0.1') {
return null
}
if (parts.length > 1 && parts[0] !== 'www') {
return parts[0]
}
return null
}
const subdomain = ref(getSubdomain())
const email = ref('')
const password = ref('')
const firstName = ref('')
@@ -106,30 +90,17 @@ const handleRegister = async () => {
error.value = ''
success.value = false
const headers: Record<string, string> = {
'Content-Type': 'application/json',
}
if (subdomain.value) {
headers['x-tenant-id'] = subdomain.value
}
const response = await fetch(`${config.public.apiBaseUrl}/api/auth/register`, {
// Use BFF proxy - subdomain/tenant is handled automatically by Nitro
await $fetch('/api/auth/register', {
method: 'POST',
headers,
body: JSON.stringify({
body: {
email: email.value,
password: password.value,
firstName: firstName.value || undefined,
lastName: lastName.value || undefined,
}),
},
})
if (!response.ok) {
const data = await response.json()
throw new Error(data.message || 'Registration failed')
}
success.value = true
// Redirect to login after 2 seconds
@@ -137,9 +108,10 @@ const handleRegister = async () => {
router.push('/login')
}, 2000)
} catch (e: any) {
error.value = e.message || 'Registration failed'
error.value = e.data?.message || e.message || 'Registration failed'
} finally {
loading.value = false
}
}
</script>