diff --git a/nextjs_space/app/auth/forgot-password/page.tsx b/nextjs_space/app/auth/forgot-password/page.tsx index 8ae87b6..2b1164b 100644 --- a/nextjs_space/app/auth/forgot-password/page.tsx +++ b/nextjs_space/app/auth/forgot-password/page.tsx @@ -1,14 +1,20 @@ -'use client'; +"use client"; -import React, { useState } from 'react'; -import Link from 'next/link'; -import { Button } from '@/components/ui/button'; -import { Input } from '@/components/ui/input'; -import { Label } from '@/components/ui/label'; -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; +import React, { useState } from "react"; +import Link from "next/link"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; export default function ForgotPasswordPage() { - const [email, setEmail] = useState(''); + const [email, setEmail] = useState(""); const [submitted, setSubmitted] = useState(false); const [loading, setLoading] = useState(false); @@ -17,9 +23,9 @@ export default function ForgotPasswordPage() { setLoading(true); try { - const response = await fetch('/api/auth/reset-password', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, + const response = await fetch("/api/auth/reset-password", { + method: "POST", + headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email }), }); @@ -28,11 +34,11 @@ export default function ForgotPasswordPage() { if (response.ok) { setSubmitted(true); } else { - alert(data.error || 'Failed to send reset email'); + alert(data.error || "Failed to send reset email"); } } catch (error) { - console.error('Password reset error:', error); - alert('Failed to send reset email'); + console.error("Password reset error:", error); + alert("Failed to send reset email"); } finally { setLoading(false); } @@ -45,7 +51,8 @@ export default function ForgotPasswordPage() { Check Your Email - If an account exists with {email}, you will receive password reset instructions shortly. + If an account exists with {email}, you will receive password reset + instructions shortly. @@ -66,7 +73,8 @@ export default function ForgotPasswordPage() { Forgot Password - Enter your email address and we'll send you instructions to reset your password. + Enter your email address and we'll send you instructions to reset + your password. @@ -88,7 +96,7 @@ export default function ForgotPasswordPage() { className="w-full bg-green-600 hover:bg-green-700" disabled={loading} > - {loading ? 'Sending...' : 'Send Reset Instructions'} + {loading ? "Sending..." : "Send Reset Instructions"}
diff --git a/nextjs_space/app/auth/login/page.tsx b/nextjs_space/app/auth/login/page.tsx index a498052..6c6c0cc 100644 --- a/nextjs_space/app/auth/login/page.tsx +++ b/nextjs_space/app/auth/login/page.tsx @@ -1,12 +1,11 @@ - -'use client'; - -import { useState, Suspense, useEffect } from 'react'; -import { useRouter, useSearchParams } from 'next/navigation'; -import { signIn, getSession } from 'next-auth/react'; -import Link from 'next/link'; -import Image from 'next/image'; -import { motion } from 'framer-motion'; +"use client"; + +import { useState, Suspense, useEffect } from "react"; +import { useRouter, useSearchParams } from "next/navigation"; +import { signIn, getSession } from "next-auth/react"; +import Link from "next/link"; +import Image from "next/image"; +import { motion } from "framer-motion"; import { LogIn, Mail, @@ -18,13 +17,13 @@ import { AlertCircle, Chrome, ArrowRight, - Store -} from 'lucide-react'; -import { Button } from '@/components/ui/button'; -import { Input } from '@/components/ui/input'; -import { Label } from '@/components/ui/label'; -import { Checkbox } from '@/components/ui/checkbox'; -import { toast } from '@/components/ui/sonner'; + Store, +} from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Checkbox } from "@/components/ui/checkbox"; +import { toast } from "@/components/ui/sonner"; interface TenantSettings { businessName: string; @@ -35,48 +34,48 @@ interface TenantSettings { function LoginForm() { const [tenantSettings, setTenantSettings] = useState({ - businessName: 'BudStack', - primaryColor: '#16a34a' + businessName: "BudStack", + primaryColor: "#16a34a", }); useEffect(() => { // Get tenant from hostname/subdomain const hostname = window.location.hostname; - const parts = hostname.split('.'); + const parts = hostname.split("."); const subdomain = parts.length >= 2 ? parts[0] : null; // Fetch tenant settings based on subdomain - if (subdomain && subdomain !== 'localhost' && subdomain !== 'www') { + if (subdomain && subdomain !== "localhost" && subdomain !== "www") { fetch(`/api/tenant/${subdomain}`) - .then(res => res.json()) - .then(data => { + .then((res) => res.json()) + .then((data) => { if (data && data.tenant) { setTenantSettings({ - businessName: data.tenant.businessName || 'BudStack', - primaryColor: data.tenant.branding?.primaryColor || '#16a34a', + businessName: data.tenant.businessName || "BudStack", + primaryColor: data.tenant.branding?.primaryColor || "#16a34a", logoUrl: data.tenant.branding?.logoUrl, - subdomain: data.tenant.subdomain + subdomain: data.tenant.subdomain, }); } }) - .catch(err => { - console.error('Failed to fetch tenant settings:', err); + .catch((err) => { + console.error("Failed to fetch tenant settings:", err); }); } else { // Fallback to platform settings for non-tenant domains - fetch('/api/super-admin/platform-settings') - .then(res => res.json()) - .then(data => { + fetch("/api/super-admin/platform-settings") + .then((res) => res.json()) + .then((data) => { if (data) { setTenantSettings({ - businessName: data.businessName || 'BudStack', - primaryColor: data.primaryColor || '#16a34a', - logoUrl: data.logoUrl + businessName: data.businessName || "BudStack", + primaryColor: data.primaryColor || "#16a34a", + logoUrl: data.logoUrl, }); } }) - .catch(err => { - console.error('Failed to fetch platform settings:', err); + .catch((err) => { + console.error("Failed to fetch platform settings:", err); }); } }, []); @@ -86,31 +85,32 @@ function LoginForm() { const [showPassword, setShowPassword] = useState(false); const [rememberMe, setRememberMe] = useState(false); const [formData, setFormData] = useState({ - email: '', - password: '' + email: "", + password: "", }); const [errors, setErrors] = useState>({}); // Check for messages from signup or other redirects - const message = searchParams?.get('message'); - const error = searchParams?.get('error'); + const message = searchParams?.get("message"); + const error = searchParams?.get("error"); const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target; - setFormData(prev => ({ ...prev, [name]: value })); + setFormData((prev) => ({ ...prev, [name]: value })); // Clear error when user starts typing if (errors[name]) { - setErrors(prev => ({ ...prev, [name]: '' })); + setErrors((prev) => ({ ...prev, [name]: "" })); } }; const validateForm = () => { const newErrors: Record = {}; - if (!formData.email.trim()) newErrors.email = 'Email is required'; - if (!/\S+@\S+\.\S+/.test(formData.email)) newErrors.email = 'Invalid email format'; - if (!formData.password) newErrors.password = 'Password is required'; + if (!formData.email.trim()) newErrors.email = "Email is required"; + if (!/\S+@\S+\.\S+/.test(formData.email)) + newErrors.email = "Invalid email format"; + if (!formData.password) newErrors.password = "Password is required"; setErrors(newErrors); return Object.keys(newErrors).length === 0; @@ -120,25 +120,25 @@ function LoginForm() { e.preventDefault(); if (!validateForm()) { - toast.error('Please fix the errors in the form'); + toast.error("Please fix the errors in the form"); return; } setIsLoading(true); try { - const result = await signIn('credentials', { + const result = await signIn("credentials", { email: formData.email, password: formData.password, redirect: false, }); if (result?.error) { - throw new Error('Invalid email or password'); + throw new Error("Invalid email or password"); } if (result?.ok) { - toast.success('Signed in successfully!'); + toast.success("Signed in successfully!"); // Get fresh session and redirect based on role const session = await getSession(); @@ -146,18 +146,17 @@ function LoginForm() { const userRole = (session.user as any).role; // Redirect based on user role - if (userRole === 'SUPER_ADMIN') { - router.replace('/super-admin'); - } else if (userRole === 'TENANT_ADMIN') { - router.replace('/tenant-admin'); + if (userRole === "SUPER_ADMIN") { + router.replace("/super-admin"); + } else if (userRole === "TENANT_ADMIN") { + router.replace("/tenant-admin"); } else { - router.replace('/dashboard'); + router.replace("/dashboard"); } } } - } catch (error: any) { - toast.error(error.message || 'An error occurred during sign in'); + toast.error(error.message || "An error occurred during sign in"); } finally { setIsLoading(false); } @@ -165,9 +164,9 @@ function LoginForm() { const handleGoogleSignIn = async () => { try { - await signIn('google', { callbackUrl: '/dashboard' }); + await signIn("google", { callbackUrl: "/dashboard" }); } catch (error) { - toast.error('Google sign in failed'); + toast.error("Google sign in failed"); } }; @@ -209,7 +208,9 @@ function LoginForm() {
-

Welcome Back

+

+ Welcome Back +

Sign in to access your account

@@ -238,9 +239,9 @@ function LoginForm() {

- {error === 'CredentialsSignin' - ? 'Invalid email or password' - : 'An error occurred during sign in'} + {error === "CredentialsSignin" + ? "Invalid email or password" + : "An error occurred during sign in"}

@@ -262,7 +263,9 @@ function LoginForm() {
- Or sign in with email + + Or sign in with email +
@@ -280,7 +283,7 @@ function LoginForm() { required value={formData.email} onChange={handleChange} - className={`pl-10 ${errors.email ? 'border-red-500' : ''}`} + className={`pl-10 ${errors.email ? "border-red-500" : ""}`} placeholder="joao@example.com" /> @@ -300,11 +303,11 @@ function LoginForm() { {errors.password && ( @@ -329,7 +336,9 @@ function LoginForm() { setRememberMe(checked as boolean)} + onCheckedChange={(checked) => + setRememberMe(checked as boolean) + } />