Files
slipmatz-web/app/components/LoginModal.vue
Frank John Begornia bf701f8342 Replace Firebase Storage with MinIO and add user account features
- Storage Integration:
  * Remove Firebase Storage dependency and useFirebaseStorage composable
  * Implement direct MinIO uploads via POST /storage/upload with multipart/form-data
  * Upload canvas JSON, preview PNG, and production PNG as separate objects
  * Store public URLs and metadata in design records

- Authentication & Registration:
  * Add email/password registration page with validation
  * Integrate backend user session via /auth/login endpoint
  * Store backendUser.id as ownerId in design records
  * Auto-sync backend session on Firebase auth state changes

- User Account Pages:
  * Create profile page showing user details and backend session info
  * Create orders page with transaction history filtered by customerEmail
  * Add server proxy /api/orders to forward GET /transactions queries

- Navigation Improvements:
  * Replace inline auth buttons with avatar dropdown menu
  * Add Profile, Orders, and Logout options to dropdown
  * Implement outside-click and route-change handlers for dropdown
  * Display user initials in avatar badge

- API Updates:
  * Update transactions endpoint to accept amount as string
  * Format amount with .toFixed(2) in checkout success flow
  * Query orders by customerEmail instead of ownerId for consistency
2025-11-16 01:19:35 +08:00

123 lines
3.6 KiB
Vue

<script setup lang="ts">
const { signInWithEmail, signInWithGoogle, error } = useAuth();
const isOpen = useLoginModal();
const email = ref("");
const password = ref("");
const loginError = ref<string | null>(null);
const isSubmitting = ref(false);
const handleEmailLogin = async () => {
try {
loginError.value = null;
isSubmitting.value = true;
await signInWithEmail(email.value, password.value);
isOpen.value = false;
// Reset form
email.value = "";
password.value = "";
} catch (err) {
loginError.value = "Login failed. Please check your credentials.";
} finally {
isSubmitting.value = false;
}
};
const handleGoogleLogin = async () => {
try {
loginError.value = null;
isSubmitting.value = true;
await signInWithGoogle();
isOpen.value = false;
} catch (err) {
loginError.value = "Google login failed. Please try again.";
} finally {
isSubmitting.value = false;
}
};
</script>
<template>
<Teleport to="body">
<div
v-if="isOpen"
class="fixed left-0 top-0 z-50 flex min-h-screen w-full items-center justify-center bg-black/60 px-4"
@click.self="isOpen = false"
>
<div class="w-full max-w-md rounded-lg bg-slate-900 p-6 shadow-xl">
<h2 class="mb-6 text-2xl font-bold text-white">Sign In</h2>
<form @submit.prevent="handleEmailLogin" class="space-y-4">
<div>
<label class="block text-sm font-medium text-slate-300"
>Email</label
>
<input
v-model="email"
type="email"
required
class="mt-1 w-full rounded-md border border-slate-700 bg-slate-800 px-3 py-2 text-white focus:border-sky-400 focus:outline-none"
/>
</div>
<div>
<label class="block text-sm font-medium text-slate-300"
>Password</label
>
<input
v-model="password"
type="password"
required
class="mt-1 w-full rounded-md border border-slate-700 bg-slate-800 px-3 py-2 text-white focus:border-sky-400 focus:outline-none"
/>
</div>
<button
type="submit"
:disabled="isSubmitting"
class="w-full rounded-md bg-sky-600 px-4 py-2 text-white hover:bg-sky-700 disabled:opacity-50"
>
{{ isSubmitting ? "Signing in..." : "Sign In" }}
</button>
</form>
<div class="my-4 flex items-center">
<div class="flex-1 border-t border-slate-700"></div>
<span class="px-3 text-sm text-slate-400">or</span>
<div class="flex-1 border-t border-slate-700"></div>
</div>
<button
@click="handleGoogleLogin"
:disabled="isSubmitting"
class="w-full rounded-md border border-slate-700 bg-slate-800 px-4 py-2 text-white hover:bg-slate-700 disabled:opacity-50"
>
Sign in with Google
</button>
<div v-if="loginError || error" class="mt-4 text-sm text-red-400">
{{ loginError || error }}
</div>
<p class="mt-4 text-sm text-slate-400">
Need an account?
<NuxtLink
to="/register"
class="text-sky-400 hover:text-sky-300"
@click="isOpen = false"
>
Create one instead
</NuxtLink>
</p>
<button
@click="isOpen = false"
class="mt-4 text-sm text-slate-400 hover:text-white"
>
Cancel
</button>
</div>
</div>
</Teleport>
</template>