2026-04-02 16:05:20 +03:00
|
|
|
"use client";
|
2026-03-17 20:36:59 +03:00
|
|
|
|
2026-04-02 16:05:20 +03:00
|
|
|
import { useState } from "react";
|
|
|
|
|
import { motion, AnimatePresence } from "framer-motion";
|
|
|
|
|
import toast, { Toaster } from "react-hot-toast";
|
|
|
|
|
import Link from "next/link";
|
|
|
|
|
import { useRouter } from "next/navigation";
|
2026-03-17 20:36:59 +03:00
|
|
|
import {
|
|
|
|
|
Mail,
|
|
|
|
|
Lock,
|
|
|
|
|
Eye,
|
|
|
|
|
EyeOff,
|
|
|
|
|
ArrowLeft,
|
|
|
|
|
LogIn,
|
|
|
|
|
CheckCircle,
|
|
|
|
|
Loader2,
|
|
|
|
|
Home,
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
Shield,
|
|
|
|
|
Phone,
|
|
|
|
|
KeyRound,
|
2026-04-02 16:05:20 +03:00
|
|
|
} from "lucide-react";
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
import {
|
|
|
|
|
loginWithEmail,
|
|
|
|
|
loginWithPhone,
|
|
|
|
|
sendEmailOTP,
|
|
|
|
|
sendPhoneOTP,
|
|
|
|
|
verifyEmail,
|
|
|
|
|
verifyPhone,
|
|
|
|
|
isEmail,
|
|
|
|
|
isPhoneNumber,
|
2026-03-29 12:42:57 +00:00
|
|
|
getOwnerByUserId,
|
|
|
|
|
getCustomerByUserId,
|
2026-04-02 16:05:20 +03:00
|
|
|
} from "../utils/api";
|
|
|
|
|
import AuthService from "../services/AuthService";
|
2026-03-17 20:36:59 +03:00
|
|
|
|
|
|
|
|
export default function LoginPage() {
|
|
|
|
|
const router = useRouter();
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
|
|
|
|
// Step: 'login' | 'otp'
|
2026-04-02 16:05:20 +03:00
|
|
|
const [step, setStep] = useState("login");
|
|
|
|
|
const [loginMethod, setLoginMethod] = useState("email"); // 'email' | 'phone'
|
2026-03-17 20:36:59 +03:00
|
|
|
const [showPassword, setShowPassword] = useState(false);
|
|
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
|
const [isSuccess, setIsSuccess] = useState(false);
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
2026-03-17 20:36:59 +03:00
|
|
|
const [formData, setFormData] = useState({
|
2026-04-02 16:05:20 +03:00
|
|
|
credential: "",
|
|
|
|
|
password: "",
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
rememberMe: false,
|
2026-03-17 20:36:59 +03:00
|
|
|
});
|
|
|
|
|
|
2026-04-02 16:05:20 +03:00
|
|
|
const [otpCode, setOtpCode] = useState("");
|
|
|
|
|
const [otpError, setOtpError] = useState("");
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
const [errors, setErrors] = useState({});
|
2026-03-17 20:36:59 +03:00
|
|
|
|
|
|
|
|
const validateForm = () => {
|
|
|
|
|
const newErrors = {};
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
|
|
|
|
if (!formData.credential) {
|
2026-04-02 16:05:20 +03:00
|
|
|
newErrors.credential =
|
|
|
|
|
loginMethod === "email"
|
|
|
|
|
? "البريد الإلكتروني مطلوب"
|
|
|
|
|
: "رقم الهاتف مطلوب";
|
|
|
|
|
// } else if (loginMethod === 'email' && !isEmail(formData.credential)) {
|
|
|
|
|
// newErrors.credential = 'البريد الإلكتروني غير صالح';
|
|
|
|
|
// } else if (loginMethod === 'phone' && !isPhoneNumber(formData.credential)) {
|
|
|
|
|
newErrors.credential = "رقم الهاتف غير صالح";
|
2026-03-17 20:36:59 +03:00
|
|
|
}
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
2026-03-17 20:36:59 +03:00
|
|
|
if (!formData.password) {
|
2026-04-02 16:05:20 +03:00
|
|
|
newErrors.password = "كلمة المرور مطلوبة";
|
2026-03-17 20:36:59 +03:00
|
|
|
}
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
2026-03-17 20:36:59 +03:00
|
|
|
setErrors(newErrors);
|
|
|
|
|
return Object.keys(newErrors).length === 0;
|
|
|
|
|
};
|
|
|
|
|
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
const handleLogin = async (e) => {
|
2026-03-17 20:36:59 +03:00
|
|
|
e.preventDefault();
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
if (!validateForm()) return;
|
|
|
|
|
|
|
|
|
|
setIsLoading(true);
|
|
|
|
|
setErrors({});
|
|
|
|
|
|
|
|
|
|
try {
|
2026-04-02 16:05:20 +03:00
|
|
|
const loginFn = loginMethod === "email" ? loginWithEmail : loginWithPhone;
|
|
|
|
|
console.log(
|
|
|
|
|
"[Login] Attempting login via",
|
|
|
|
|
loginMethod,
|
|
|
|
|
":",
|
|
|
|
|
formData.credential,
|
|
|
|
|
);
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
|
|
|
|
const result = await loginFn(formData.credential, formData.password);
|
|
|
|
|
|
2026-04-02 16:05:20 +03:00
|
|
|
console.log("[Login] Response status:", result.status);
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
|
|
|
|
if (result.status === 200) {
|
2026-04-02 16:05:20 +03:00
|
|
|
const token =
|
|
|
|
|
typeof result.data === "string"
|
|
|
|
|
? result.data
|
|
|
|
|
: result.data?.token || result.data?.accessToken;
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
AuthService.addToken(token);
|
2026-04-02 16:05:20 +03:00
|
|
|
console.log("[Login] Token stored");
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
2026-03-29 12:42:57 +00:00
|
|
|
// Fetch user profile to get full name
|
2026-03-28 14:15:40 +00:00
|
|
|
const authUser = AuthService.getUser();
|
2026-03-29 12:42:57 +00:00
|
|
|
if (authUser?.id) {
|
|
|
|
|
try {
|
|
|
|
|
const isOwner = AuthService.isOwner();
|
|
|
|
|
const fetchFn = isOwner ? getOwnerByUserId : getCustomerByUserId;
|
|
|
|
|
const profile = await fetchFn(authUser.id);
|
|
|
|
|
if (profile) {
|
|
|
|
|
AuthService.cacheUser({
|
2026-04-02 16:05:20 +03:00
|
|
|
name:
|
|
|
|
|
profile.fullName ||
|
|
|
|
|
profile.name ||
|
|
|
|
|
`${profile.firstName || ""} ${profile.lastName || ""}`.trim(),
|
2026-03-29 12:42:57 +00:00
|
|
|
email: profile.email || authUser.email,
|
|
|
|
|
phone: profile.phone || profile.phoneNumber || authUser.phone,
|
|
|
|
|
});
|
2026-04-02 16:05:20 +03:00
|
|
|
console.log("[Login] User profile cached");
|
2026-03-29 12:42:57 +00:00
|
|
|
}
|
|
|
|
|
} catch (err) {
|
2026-04-02 16:05:20 +03:00
|
|
|
console.warn("[Login] Failed to fetch profile:", err);
|
2026-03-29 12:42:57 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-02 16:05:20 +03:00
|
|
|
const userRole = AuthService.isAdmin()
|
|
|
|
|
? "admin"
|
|
|
|
|
: AuthService.isOwner()
|
|
|
|
|
? "owner"
|
|
|
|
|
: "customer";
|
|
|
|
|
console.log("[Login] User role:", userRole);
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
|
|
|
|
setIsSuccess(true);
|
2026-04-02 16:05:20 +03:00
|
|
|
toast.success("تم تسجيل الدخول بنجاح!", {
|
|
|
|
|
style: { background: "#dcfce7", color: "#166534" },
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2026-04-02 16:05:20 +03:00
|
|
|
if (userRole === "admin") {
|
|
|
|
|
router.push("/admin");
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
} else {
|
2026-04-02 16:05:20 +03:00
|
|
|
router.push("/");
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}
|
|
|
|
|
}, 1500);
|
|
|
|
|
} else if (result.status === 206) {
|
2026-04-02 16:05:20 +03:00
|
|
|
console.log("[Login] 206 — OTP required");
|
|
|
|
|
const tempToken =
|
|
|
|
|
typeof result.data === "string"
|
|
|
|
|
? result.data
|
|
|
|
|
: result.data?.token || result.data?.accessToken;
|
2026-03-28 16:38:04 +00:00
|
|
|
if (tempToken) {
|
|
|
|
|
AuthService.addToken(tempToken);
|
2026-04-02 16:05:20 +03:00
|
|
|
console.log("[Login] Temp token stored for OTP");
|
2026-03-28 16:38:04 +00:00
|
|
|
}
|
2026-04-02 16:05:20 +03:00
|
|
|
toast("يرجى إدخال رمز التحقق", {
|
|
|
|
|
icon: "🔐",
|
|
|
|
|
style: { background: "#fef3c7", color: "#92400e" },
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Send OTP
|
|
|
|
|
try {
|
2026-04-02 16:05:20 +03:00
|
|
|
if (loginMethod === "email") {
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
await sendEmailOTP();
|
|
|
|
|
} else {
|
|
|
|
|
await sendPhoneOTP();
|
|
|
|
|
}
|
2026-04-02 16:05:20 +03:00
|
|
|
console.log("[Login] OTP sent successfully");
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
} catch (otpErr) {
|
2026-04-02 16:05:20 +03:00
|
|
|
console.warn("[Login] OTP send failed, proceeding anyway:", otpErr);
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
2026-04-02 16:05:20 +03:00
|
|
|
setStep("otp");
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
} else {
|
|
|
|
|
// Other error
|
2026-04-02 16:05:20 +03:00
|
|
|
console.error("[Login] Unexpected status:", result.status, result.data);
|
|
|
|
|
toast.error(
|
|
|
|
|
result.data?.message || result.data || "بيانات الدخول غير صحيحة",
|
|
|
|
|
{
|
|
|
|
|
style: { background: "#fee2e2", color: "#991b1b" },
|
|
|
|
|
},
|
|
|
|
|
);
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}
|
|
|
|
|
} catch (err) {
|
2026-04-02 16:05:20 +03:00
|
|
|
console.error("[Login] Error:", err);
|
|
|
|
|
toast.error(err.message || "حدث خطأ في الاتصال", {
|
|
|
|
|
style: { background: "#fee2e2", color: "#991b1b" },
|
2026-03-17 20:36:59 +03:00
|
|
|
});
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
} finally {
|
|
|
|
|
setIsLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleVerifyOTP = async (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (!otpCode || otpCode.length < 4) {
|
2026-04-02 16:05:20 +03:00
|
|
|
setOtpError("يرجى إدخال رمز التحقق");
|
2026-03-17 20:36:59 +03:00
|
|
|
return;
|
|
|
|
|
}
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
2026-03-17 20:36:59 +03:00
|
|
|
setIsLoading(true);
|
2026-04-02 16:05:20 +03:00
|
|
|
setOtpError("");
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
|
|
|
|
try {
|
2026-04-02 16:05:20 +03:00
|
|
|
const verifyFn = loginMethod === "email" ? verifyEmail : verifyPhone;
|
|
|
|
|
console.log("[OTP] Verifying code:", otpCode);
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
|
|
|
|
const result = await verifyFn(otpCode);
|
2026-04-02 16:05:20 +03:00
|
|
|
console.log("[OTP] Verify response status:", result.status);
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
|
|
|
|
if (result.ok) {
|
2026-04-02 16:05:20 +03:00
|
|
|
const finalToken =
|
|
|
|
|
typeof result.data === "string"
|
|
|
|
|
? result.data
|
|
|
|
|
: result.data?.token || result.data?.accessToken;
|
|
|
|
|
if (finalToken && typeof finalToken === "string") {
|
2026-03-28 16:38:04 +00:00
|
|
|
AuthService.addToken(finalToken);
|
2026-04-02 16:05:20 +03:00
|
|
|
console.log("[OTP] Final token stored");
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-17 20:36:59 +03:00
|
|
|
setIsSuccess(true);
|
2026-04-02 16:05:20 +03:00
|
|
|
toast.success("تم التحقق بنجاح!", {
|
|
|
|
|
style: { background: "#dcfce7", color: "#166534" },
|
2026-03-17 20:36:59 +03:00
|
|
|
});
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
2026-03-17 20:36:59 +03:00
|
|
|
setTimeout(() => {
|
2026-04-02 16:05:20 +03:00
|
|
|
console.log("[OTP] Redirecting to home");
|
|
|
|
|
router.push("/");
|
2026-03-17 20:36:59 +03:00
|
|
|
}, 1500);
|
|
|
|
|
} else {
|
2026-04-02 16:05:20 +03:00
|
|
|
console.error("[OTP] Verification failed:", result.data);
|
|
|
|
|
setOtpError(result.data?.message || "رمز التحقق غير صحيح");
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}
|
|
|
|
|
} catch (err) {
|
2026-04-02 16:05:20 +03:00
|
|
|
console.error("[OTP] Error:", err);
|
|
|
|
|
setOtpError(err.message || "حدث خطأ في التحقق");
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
} finally {
|
|
|
|
|
setIsLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const resendOTP = async () => {
|
|
|
|
|
try {
|
2026-04-02 16:05:20 +03:00
|
|
|
console.log("[OTP] Resending OTP via", loginMethod);
|
|
|
|
|
if (loginMethod === "email") {
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
await sendEmailOTP();
|
|
|
|
|
} else {
|
|
|
|
|
await sendPhoneOTP();
|
2026-03-17 20:36:59 +03:00
|
|
|
}
|
2026-04-02 16:05:20 +03:00
|
|
|
toast.success("تم إرسال رمز التحقق مجدداً", {
|
|
|
|
|
style: { background: "#dcfce7", color: "#166534" },
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
});
|
|
|
|
|
} catch (err) {
|
2026-04-02 16:05:20 +03:00
|
|
|
console.error("[OTP] Resend failed:", err);
|
|
|
|
|
toast.error("فشل إرسال الرمز");
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Auto-detect login method from input
|
|
|
|
|
const handleCredentialChange = (value) => {
|
|
|
|
|
setFormData({ ...formData, credential: value });
|
|
|
|
|
if (errors.credential) setErrors({ ...errors, credential: null });
|
|
|
|
|
|
|
|
|
|
// Auto-switch method
|
2026-04-02 16:00:05 +03:00
|
|
|
// if (isEmail(value)) {
|
|
|
|
|
// setLoginMethod('email');
|
|
|
|
|
// } else if (isPhoneNumber(value)) {
|
|
|
|
|
// setLoginMethod('phone');
|
|
|
|
|
// }
|
2026-03-17 20:36:59 +03:00
|
|
|
};
|
|
|
|
|
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
const particles = Array.from({ length: 20 }, (_, i) => ({
|
2026-03-17 20:36:59 +03:00
|
|
|
id: i,
|
|
|
|
|
x: Math.random() * 100,
|
|
|
|
|
y: Math.random() * 100,
|
|
|
|
|
size: Math.random() * 3 + 1,
|
|
|
|
|
duration: Math.random() * 15 + 10,
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
delay: Math.random() * 5,
|
2026-03-17 20:36:59 +03:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const containerVariants = {
|
|
|
|
|
hidden: { opacity: 0 },
|
|
|
|
|
visible: {
|
|
|
|
|
opacity: 1,
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
transition: { staggerChildren: 0.1, delayChildren: 0.2 },
|
|
|
|
|
},
|
2026-03-17 20:36:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const itemVariants = {
|
|
|
|
|
hidden: { y: 20, opacity: 0 },
|
|
|
|
|
visible: {
|
|
|
|
|
y: 0,
|
|
|
|
|
opacity: 1,
|
2026-04-02 16:05:20 +03:00
|
|
|
transition: { type: "spring", stiffness: 100 },
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
},
|
2026-03-17 20:36:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="min-h-screen bg-gradient-to-br from-gray-950 via-gray-900 to-gray-950 flex items-center justify-center p-4 relative overflow-hidden">
|
|
|
|
|
<Toaster position="top-center" reverseOrder={false} />
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
|
|
|
|
{/* Particles */}
|
2026-03-17 20:36:59 +03:00
|
|
|
<div className="absolute inset-0 overflow-hidden">
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
{particles.map((p) => (
|
2026-03-17 20:36:59 +03:00
|
|
|
<motion.div
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
key={p.id}
|
2026-03-17 20:36:59 +03:00
|
|
|
className="absolute rounded-full bg-amber-500/20"
|
2026-04-02 16:05:20 +03:00
|
|
|
style={{
|
|
|
|
|
left: `${p.x}%`,
|
|
|
|
|
top: `${p.y}%`,
|
|
|
|
|
width: p.size,
|
|
|
|
|
height: p.size,
|
|
|
|
|
}}
|
|
|
|
|
animate={{
|
|
|
|
|
y: [0, -20, 0],
|
|
|
|
|
x: [0, 10, -10, 0],
|
|
|
|
|
opacity: [0.2, 0.4, 0.2],
|
|
|
|
|
}}
|
|
|
|
|
transition={{
|
|
|
|
|
duration: p.duration,
|
|
|
|
|
repeat: Infinity,
|
|
|
|
|
delay: p.delay,
|
|
|
|
|
ease: "linear",
|
|
|
|
|
}}
|
2026-03-17 20:36:59 +03:00
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
{/* Glow orbs */}
|
2026-03-17 20:36:59 +03:00
|
|
|
<motion.div
|
|
|
|
|
className="absolute top-20 left-20 w-64 h-64 bg-amber-500/10 rounded-full blur-3xl"
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
animate={{ scale: [1, 1.2, 1], x: [0, 30, 0], y: [0, -20, 0] }}
|
2026-03-17 20:36:59 +03:00
|
|
|
transition={{ duration: 12, repeat: Infinity }}
|
|
|
|
|
/>
|
|
|
|
|
<motion.div
|
|
|
|
|
className="absolute bottom-20 right-20 w-80 h-80 bg-blue-500/10 rounded-full blur-3xl"
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
animate={{ scale: [1, 1.3, 1], x: [0, -30, 0], y: [0, 20, 0] }}
|
2026-03-17 20:36:59 +03:00
|
|
|
transition={{ duration: 15, repeat: Infinity }}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<motion.div
|
|
|
|
|
variants={containerVariants}
|
|
|
|
|
initial="hidden"
|
|
|
|
|
animate="visible"
|
|
|
|
|
className="relative w-full max-w-md z-10"
|
|
|
|
|
>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
{/* Back link */}
|
|
|
|
|
<motion.div variants={itemVariants} className="absolute -top-16 left-0">
|
2026-04-02 16:05:20 +03:00
|
|
|
<Link
|
|
|
|
|
href="/"
|
|
|
|
|
className="group flex items-center gap-2 text-gray-400 hover:text-white transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<motion.div
|
|
|
|
|
whileHover={{ x: -5 }}
|
|
|
|
|
transition={{ type: "spring", stiffness: 400 }}
|
|
|
|
|
>
|
2026-03-17 20:36:59 +03:00
|
|
|
<ArrowLeft className="w-4 h-4" />
|
|
|
|
|
</motion.div>
|
|
|
|
|
<span>العودة للرئيسية</span>
|
|
|
|
|
</Link>
|
|
|
|
|
</motion.div>
|
|
|
|
|
|
|
|
|
|
<motion.div
|
|
|
|
|
variants={itemVariants}
|
|
|
|
|
className="bg-white/10 backdrop-blur-2xl rounded-3xl shadow-2xl border border-white/10 overflow-hidden"
|
|
|
|
|
>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
{/* Header */}
|
2026-03-17 20:36:59 +03:00
|
|
|
<div className="bg-gradient-to-r from-amber-500 to-amber-600 p-8 text-center relative overflow-hidden">
|
|
|
|
|
<motion.div
|
|
|
|
|
initial={{ scale: 0 }}
|
|
|
|
|
animate={{ scale: 1 }}
|
2026-04-02 16:05:20 +03:00
|
|
|
transition={{ delay: 0.2, type: "spring" }}
|
2026-03-17 20:36:59 +03:00
|
|
|
className="absolute -top-10 -right-10 w-40 h-40 bg-white/10 rounded-full"
|
|
|
|
|
/>
|
|
|
|
|
<motion.div
|
|
|
|
|
initial={{ scale: 0 }}
|
|
|
|
|
animate={{ scale: 1 }}
|
2026-04-02 16:05:20 +03:00
|
|
|
transition={{ delay: 0.3, type: "spring" }}
|
2026-03-17 20:36:59 +03:00
|
|
|
className="absolute -bottom-10 -left-10 w-40 h-40 bg-white/10 rounded-full"
|
|
|
|
|
/>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
2026-04-02 16:05:20 +03:00
|
|
|
<motion.div
|
|
|
|
|
initial={{ y: 20, opacity: 0 }}
|
|
|
|
|
animate={{ y: 0, opacity: 1 }}
|
|
|
|
|
transition={{ delay: 0.2 }}
|
|
|
|
|
className="relative z-10"
|
|
|
|
|
>
|
2026-03-17 20:36:59 +03:00
|
|
|
<motion.div
|
|
|
|
|
animate={{ rotate: [0, 10, -10, 0] }}
|
|
|
|
|
transition={{ duration: 2, repeat: Infinity }}
|
|
|
|
|
className="w-20 h-20 mx-auto mb-4 bg-white/20 rounded-2xl flex items-center justify-center backdrop-blur-sm"
|
|
|
|
|
>
|
2026-04-02 16:05:20 +03:00
|
|
|
{step === "otp" ? (
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
<KeyRound className="w-10 h-10 text-white" />
|
|
|
|
|
) : (
|
|
|
|
|
<Home className="w-10 h-10 text-white" />
|
|
|
|
|
)}
|
2026-03-17 20:36:59 +03:00
|
|
|
</motion.div>
|
|
|
|
|
<h1 className="text-3xl font-bold text-white mb-2">SweetHome</h1>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
<p className="text-amber-100">
|
2026-04-02 16:05:20 +03:00
|
|
|
{step === "otp" ? "أدخل رمز التحقق" : "مرحباً بعودتك!"}
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
</p>
|
2026-03-17 20:36:59 +03:00
|
|
|
</motion.div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="p-8">
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
<AnimatePresence mode="wait">
|
2026-04-02 16:05:20 +03:00
|
|
|
{step === "login" ? (
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
<motion.form
|
|
|
|
|
key="login"
|
|
|
|
|
initial={{ opacity: 0, x: -20 }}
|
|
|
|
|
animate={{ opacity: 1, x: 0 }}
|
|
|
|
|
exit={{ opacity: 0, x: 20 }}
|
|
|
|
|
onSubmit={handleLogin}
|
|
|
|
|
className="space-y-6"
|
|
|
|
|
>
|
|
|
|
|
{/* Login method tabs */}
|
|
|
|
|
<div className="flex gap-2 bg-white/5 p-1 rounded-xl">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => {
|
2026-04-02 16:05:20 +03:00
|
|
|
setLoginMethod("email");
|
|
|
|
|
setFormData({ ...formData, credential: "" });
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}}
|
|
|
|
|
className={`flex-1 py-2.5 rounded-lg text-sm font-medium transition-all flex items-center justify-center gap-2 ${
|
2026-04-02 16:05:20 +03:00
|
|
|
loginMethod === "email"
|
|
|
|
|
? "bg-amber-500 text-white shadow-lg"
|
|
|
|
|
: "text-gray-400 hover:text-white"
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}`}
|
2026-03-17 20:36:59 +03:00
|
|
|
>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
<Mail className="w-4 h-4" />
|
|
|
|
|
بريد إلكتروني
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => {
|
2026-04-02 16:05:20 +03:00
|
|
|
setLoginMethod("phone");
|
|
|
|
|
setFormData({ ...formData, credential: "" });
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}}
|
|
|
|
|
className={`flex-1 py-2.5 rounded-lg text-sm font-medium transition-all flex items-center justify-center gap-2 ${
|
2026-04-02 16:05:20 +03:00
|
|
|
loginMethod === "phone"
|
|
|
|
|
? "bg-amber-500 text-white shadow-lg"
|
|
|
|
|
: "text-gray-400 hover:text-white"
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
<Phone className="w-4 h-4" />
|
|
|
|
|
رقم الهاتف
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2026-03-17 20:36:59 +03:00
|
|
|
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
{/* Credential input */}
|
|
|
|
|
<div>
|
|
|
|
|
<label className="block text-sm font-medium text-gray-300 mb-2">
|
2026-04-02 16:05:20 +03:00
|
|
|
{loginMethod === "email"
|
|
|
|
|
? "البريد الإلكتروني"
|
|
|
|
|
: "رقم الهاتف"}
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
</label>
|
|
|
|
|
<div className="relative group">
|
|
|
|
|
<div className="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
|
2026-04-02 16:05:20 +03:00
|
|
|
{loginMethod === "email" ? (
|
|
|
|
|
<Mail
|
|
|
|
|
className={`w-5 h-5 transition-colors ${errors.credential ? "text-red-500" : "text-gray-400 group-focus-within:text-amber-500"}`}
|
|
|
|
|
/>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
) : (
|
2026-04-02 16:05:20 +03:00
|
|
|
<Phone
|
|
|
|
|
className={`w-5 h-5 transition-colors ${errors.credential ? "text-red-500" : "text-gray-400 group-focus-within:text-amber-500"}`}
|
|
|
|
|
/>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<input
|
2026-04-02 16:05:20 +03:00
|
|
|
type="text"
|
|
|
|
|
// type={loginMethod === 'email' ? 'email' : 'tel'}
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
value={formData.credential}
|
|
|
|
|
onChange={(e) => handleCredentialChange(e.target.value)}
|
|
|
|
|
className={`w-full pr-12 pl-4 py-4 bg-white/5 border rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent text-white placeholder-gray-500 transition-all ${
|
2026-04-02 16:05:20 +03:00
|
|
|
errors.credential
|
|
|
|
|
? "border-red-500"
|
|
|
|
|
: "border-gray-700"
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}`}
|
2026-04-02 16:05:20 +03:00
|
|
|
placeholder={
|
|
|
|
|
loginMethod === "email"
|
|
|
|
|
? "example@email.com"
|
|
|
|
|
: "+963XXXXXXXXX"
|
|
|
|
|
}
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
dir="ltr"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
{errors.credential && (
|
2026-04-02 16:05:20 +03:00
|
|
|
<motion.p
|
|
|
|
|
initial={{ opacity: 0, y: -10 }}
|
|
|
|
|
animate={{ opacity: 1, y: 0 }}
|
|
|
|
|
className="text-red-500 text-sm mt-1"
|
|
|
|
|
>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
{errors.credential}
|
|
|
|
|
</motion.p>
|
|
|
|
|
)}
|
2026-03-17 20:36:59 +03:00
|
|
|
</div>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
|
|
|
|
{/* Password */}
|
|
|
|
|
<div>
|
2026-04-02 16:05:20 +03:00
|
|
|
<label className="block text-sm font-medium text-gray-300 mb-2">
|
|
|
|
|
كلمة المرور
|
|
|
|
|
</label>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
<div className="relative group">
|
|
|
|
|
<div className="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
|
2026-04-02 16:05:20 +03:00
|
|
|
<Lock
|
|
|
|
|
className={`w-5 h-5 transition-colors ${errors.password ? "text-red-500" : "text-gray-400 group-focus-within:text-amber-500"}`}
|
|
|
|
|
/>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
</div>
|
|
|
|
|
<input
|
2026-04-02 16:05:20 +03:00
|
|
|
type={showPassword ? "text" : "password"}
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
value={formData.password}
|
|
|
|
|
onChange={(e) => {
|
2026-04-02 16:05:20 +03:00
|
|
|
setFormData({
|
|
|
|
|
...formData,
|
|
|
|
|
password: e.target.value,
|
|
|
|
|
});
|
|
|
|
|
if (errors.password)
|
|
|
|
|
setErrors({ ...errors, password: null });
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}}
|
|
|
|
|
className={`w-full pr-12 pl-12 py-4 bg-white/5 border rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent text-white placeholder-gray-500 transition-all ${
|
2026-04-02 16:05:20 +03:00
|
|
|
errors.password ? "border-red-500" : "border-gray-700"
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}`}
|
|
|
|
|
placeholder="أدخل كلمة المرور"
|
|
|
|
|
/>
|
2026-04-02 16:05:20 +03:00
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setShowPassword(!showPassword)}
|
|
|
|
|
className="absolute inset-y-0 left-0 pl-3 flex items-center"
|
|
|
|
|
>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
{showPassword ? (
|
|
|
|
|
<EyeOff className="w-5 h-5 text-gray-400 hover:text-gray-300 transition-colors" />
|
|
|
|
|
) : (
|
|
|
|
|
<Eye className="w-5 h-5 text-gray-400 hover:text-gray-300 transition-colors" />
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
{errors.password && (
|
2026-04-02 16:05:20 +03:00
|
|
|
<motion.p
|
|
|
|
|
initial={{ opacity: 0, y: -10 }}
|
|
|
|
|
animate={{ opacity: 1, y: 0 }}
|
|
|
|
|
className="text-red-500 text-sm mt-1"
|
|
|
|
|
>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
{errors.password}
|
|
|
|
|
</motion.p>
|
2026-03-17 20:36:59 +03:00
|
|
|
)}
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
</div>
|
2026-03-17 20:36:59 +03:00
|
|
|
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
{/* Remember + Forgot */}
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<label className="flex items-center gap-2 cursor-pointer group">
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
checked={formData.rememberMe}
|
2026-04-02 16:05:20 +03:00
|
|
|
onChange={(e) =>
|
|
|
|
|
setFormData({
|
|
|
|
|
...formData,
|
|
|
|
|
rememberMe: e.target.checked,
|
|
|
|
|
})
|
|
|
|
|
}
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
className="w-4 h-4 rounded border-gray-600 bg-white/5 text-amber-500 focus:ring-amber-500 focus:ring-offset-0"
|
|
|
|
|
/>
|
2026-04-02 16:05:20 +03:00
|
|
|
<span className="text-sm text-gray-400 group-hover:text-white transition-colors">
|
|
|
|
|
تذكرني
|
|
|
|
|
</span>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
</label>
|
2026-04-02 16:05:20 +03:00
|
|
|
<Link
|
|
|
|
|
href="/forgot-password"
|
|
|
|
|
className="text-sm text-amber-400 hover:text-amber-300 transition-colors"
|
|
|
|
|
>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
نسيت كلمة المرور؟
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
2026-03-17 20:36:59 +03:00
|
|
|
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
{/* Submit */}
|
|
|
|
|
<motion.button
|
|
|
|
|
type="submit"
|
|
|
|
|
disabled={isLoading || isSuccess}
|
|
|
|
|
className="relative w-full bg-gradient-to-r from-amber-500 to-amber-600 text-white py-4 rounded-xl font-bold text-lg overflow-hidden group disabled:opacity-50 disabled:cursor-not-allowed"
|
|
|
|
|
whileHover={{ scale: 1.02 }}
|
|
|
|
|
whileTap={{ scale: 0.98 }}
|
|
|
|
|
>
|
|
|
|
|
<span className="relative z-10 flex items-center justify-center gap-2">
|
|
|
|
|
{isLoading ? (
|
|
|
|
|
<>
|
|
|
|
|
<Loader2 className="w-5 h-5 animate-spin" />
|
|
|
|
|
جاري تسجيل الدخول...
|
|
|
|
|
</>
|
|
|
|
|
) : isSuccess ? (
|
|
|
|
|
<>
|
|
|
|
|
<CheckCircle className="w-5 h-5" />
|
|
|
|
|
تم بنجاح!
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<LogIn className="w-5 h-5" />
|
|
|
|
|
تسجيل الدخول
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
</motion.button>
|
|
|
|
|
</motion.form>
|
|
|
|
|
) : (
|
|
|
|
|
/* OTP Verification Step */
|
|
|
|
|
<motion.form
|
|
|
|
|
key="otp"
|
|
|
|
|
initial={{ opacity: 0, x: 20 }}
|
|
|
|
|
animate={{ opacity: 1, x: 0 }}
|
|
|
|
|
exit={{ opacity: 0, x: -20 }}
|
|
|
|
|
onSubmit={handleVerifyOTP}
|
|
|
|
|
className="space-y-6"
|
2026-03-17 20:36:59 +03:00
|
|
|
>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
<div className="text-center mb-4">
|
|
|
|
|
<Shield className="w-12 h-12 text-amber-500 mx-auto mb-3" />
|
|
|
|
|
<p className="text-gray-300 text-sm">
|
2026-04-02 16:05:20 +03:00
|
|
|
تم إرسال رمز التحقق إلى{" "}
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
<span className="text-white font-medium" dir="ltr">
|
|
|
|
|
{formData.credential}
|
|
|
|
|
</span>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
2026-03-17 20:36:59 +03:00
|
|
|
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
<div>
|
2026-04-02 16:05:20 +03:00
|
|
|
<label className="block text-sm font-medium text-gray-300 mb-2">
|
|
|
|
|
رمز التحقق
|
|
|
|
|
</label>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
value={otpCode}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setOtpCode(e.target.value);
|
2026-04-02 16:05:20 +03:00
|
|
|
if (otpError) setOtpError("");
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}}
|
|
|
|
|
className={`w-full px-4 py-4 bg-white/5 border rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent text-white text-center text-2xl tracking-[0.5em] placeholder-gray-500 transition-all ${
|
2026-04-02 16:05:20 +03:00
|
|
|
otpError ? "border-red-500" : "border-gray-700"
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}`}
|
|
|
|
|
placeholder="______"
|
|
|
|
|
maxLength={6}
|
|
|
|
|
dir="ltr"
|
|
|
|
|
/>
|
|
|
|
|
{otpError && (
|
2026-04-02 16:05:20 +03:00
|
|
|
<motion.p
|
|
|
|
|
initial={{ opacity: 0, y: -10 }}
|
|
|
|
|
animate={{ opacity: 1, y: 0 }}
|
|
|
|
|
className="text-red-500 text-sm mt-1 text-center"
|
|
|
|
|
>
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
{otpError}
|
|
|
|
|
</motion.p>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<motion.button
|
|
|
|
|
type="submit"
|
|
|
|
|
disabled={isLoading || isSuccess}
|
|
|
|
|
className="relative w-full bg-gradient-to-r from-amber-500 to-amber-600 text-white py-4 rounded-xl font-bold text-lg disabled:opacity-50 disabled:cursor-not-allowed"
|
|
|
|
|
whileHover={{ scale: 1.02 }}
|
|
|
|
|
whileTap={{ scale: 0.98 }}
|
|
|
|
|
>
|
|
|
|
|
<span className="flex items-center justify-center gap-2">
|
|
|
|
|
{isLoading ? (
|
|
|
|
|
<>
|
|
|
|
|
<Loader2 className="w-5 h-5 animate-spin" />
|
|
|
|
|
جاري التحقق...
|
|
|
|
|
</>
|
|
|
|
|
) : isSuccess ? (
|
|
|
|
|
<>
|
|
|
|
|
<CheckCircle className="w-5 h-5" />
|
|
|
|
|
تم بنجاح!
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<KeyRound className="w-5 h-5" />
|
|
|
|
|
تحقق
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
</motion.button>
|
|
|
|
|
|
|
|
|
|
<div className="flex items-center justify-between text-sm">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => {
|
2026-04-02 16:05:20 +03:00
|
|
|
setStep("login");
|
|
|
|
|
setOtpCode("");
|
|
|
|
|
setOtpError("");
|
|
|
|
|
console.log("[OTP] Going back to login");
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}}
|
|
|
|
|
className="text-gray-400 hover:text-white transition-colors"
|
|
|
|
|
>
|
|
|
|
|
← العودة
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={resendOTP}
|
|
|
|
|
className="text-amber-400 hover:text-amber-300 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
إعادة إرسال الرمز
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</motion.form>
|
|
|
|
|
)}
|
|
|
|
|
</AnimatePresence>
|
|
|
|
|
|
2026-04-02 16:05:20 +03:00
|
|
|
<motion.p
|
|
|
|
|
variants={itemVariants}
|
|
|
|
|
className="text-center text-gray-400 mt-6"
|
|
|
|
|
>
|
|
|
|
|
ليس لديك حساب؟{" "}
|
|
|
|
|
<Link
|
|
|
|
|
href="/auth/choose-role"
|
|
|
|
|
className="text-amber-400 hover:text-amber-300 font-medium transition-colors"
|
|
|
|
|
>
|
2026-03-17 20:36:59 +03:00
|
|
|
إنشاء حساب جديد
|
|
|
|
|
</Link>
|
|
|
|
|
</motion.p>
|
|
|
|
|
</div>
|
|
|
|
|
</motion.div>
|
|
|
|
|
|
2026-04-02 16:05:20 +03:00
|
|
|
<motion.p
|
|
|
|
|
variants={itemVariants}
|
|
|
|
|
className="text-center text-gray-500 text-xs mt-4"
|
|
|
|
|
>
|
|
|
|
|
بتسجيل الدخول، أنت توافق على{" "}
|
|
|
|
|
<Link
|
|
|
|
|
href="/terms"
|
|
|
|
|
className="text-amber-400 hover:text-amber-300 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
شروط الاستخدام
|
|
|
|
|
</Link>{" "}
|
|
|
|
|
و{" "}
|
|
|
|
|
<Link
|
|
|
|
|
href="/privacy"
|
|
|
|
|
className="text-amber-400 hover:text-amber-300 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
سياسة الخصوصية
|
|
|
|
|
</Link>
|
2026-03-17 20:36:59 +03:00
|
|
|
</motion.p>
|
|
|
|
|
</motion.div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}
|