WIP - added front end auth

This commit is contained in:
Francisco Gaona
2025-12-21 09:38:51 +01:00
parent fbfaf7bb9f
commit 1d610f0d2b
22 changed files with 558 additions and 88 deletions

View File

@@ -1,3 +1,6 @@
<script setup lang="ts">
</script>
<template>
<NuxtLayout name="default">
<div class="text-center space-y-6">

View File

@@ -1,6 +1,25 @@
<script setup lang="ts">
import { LayoutGrid } from 'lucide-vue-next'
import LoginForm from '@/components/LoginForm.vue'
// Skip auth middleware for login page
definePageMeta({
auth: false
})
const { toast } = useToast()
// Check for auth message from cookie
const authMessage = useCookie('authMessage')
onMounted(() => {
if (authMessage.value) {
console.log('Displaying auth message: ' + authMessage.value)
toast.error(authMessage.value)
// Clear the message after displaying
authMessage.value = null
}
})
</script>
<template>

View File

@@ -17,11 +17,6 @@
</div>
<form @submit.prevent="handleRegister" class="space-y-4">
<div class="space-y-2">
<Label for="tenantId">Tenant ID</Label>
<Input id="tenantId" v-model="tenantId" type="text" required placeholder="123" />
</div>
<div class="space-y-2">
<Label for="email">Email</Label>
<Input
@@ -74,10 +69,29 @@
</template>
<script setup lang="ts">
// Skip auth middleware for register page
definePageMeta({
auth: false
})
const config = useRuntimeConfig()
const router = useRouter()
const tenantId = ref('123')
// 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('')
@@ -92,12 +106,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`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-tenant-id': tenantId.value,
},
headers,
body: JSON.stringify({
email: email.value,
password: password.value,