feat : kavenegar otp added

This commit is contained in:
soroush.asadi
2026-05-29 10:18:47 +03:30
parent 27e61d257e
commit 16cff8730b
22 changed files with 502 additions and 34 deletions
+13 -3
View File
@@ -2,7 +2,7 @@
import { useState } from "react";
import { useTranslations } from "next-intl";
import { useRouter } from "@/i18n/routing";
import { useRouter, Link } from "@/i18n/routing";
import { apiPost, ApiClientError } from "@/lib/api/client";
import type { AuthTokenResponse } from "@/lib/api/types";
import { useAuthStore } from "@/lib/stores/auth.store";
@@ -27,8 +27,6 @@ export default function LoginPage() {
switch (err.code) {
case "RATE_LIMITED":
return t("rateLimited");
case "NOT_FOUND":
return t("notFound");
case "SMS_FAILED":
return t("smsFailed");
case "INVALID_OTP":
@@ -47,6 +45,11 @@ export default function LoginPage() {
await apiPost("/api/auth/send-otp", { phone });
setStep("otp");
} catch (e) {
if (e instanceof ApiClientError && e.code === "NOT_FOUND") {
// No account → take them to register with phone pre-filled
router.push(`/register?phone=${encodeURIComponent(phone)}`);
return;
}
setError(authErrorMessage(e));
} finally {
setLoading(false);
@@ -137,6 +140,13 @@ export default function LoginPage() {
{error && (
<p className="text-center text-sm text-destructive">{error}</p>
)}
<p className="text-center text-sm text-muted-foreground">
{t("noAccount")}{" "}
<Link href="/register" className="font-medium text-primary hover:underline">
{t("registerLink")}
</Link>
</p>
</CardContent>
</Card>
</div>