fix(auth): make login password first
This commit is contained in:
@@ -28,7 +28,7 @@ export const en = {
|
|||||||
login: {
|
login: {
|
||||||
welcome: (title: string = "Qlockifiy") => `Welcome to ${title}`,
|
welcome: (title: string = "Qlockifiy") => `Welcome to ${title}`,
|
||||||
loginTitle: "Sign in to your account",
|
loginTitle: "Sign in to your account",
|
||||||
loginDescription: "Enter your mobile number and we will send a one-time code.",
|
loginDescription: "Enter your mobile number to continue with password login.",
|
||||||
loginCta: "Login",
|
loginCta: "Login",
|
||||||
createAccount: "Create account",
|
createAccount: "Create account",
|
||||||
haveNoAccount: "Need an account?",
|
haveNoAccount: "Need an account?",
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export const fa = {
|
|||||||
|
|
||||||
login: {
|
login: {
|
||||||
loginTitle: "ورود به حساب",
|
loginTitle: "ورود به حساب",
|
||||||
loginDescription: "شماره موبایل خود را وارد کنید تا کد یکبار مصرف برای شما ارسال شود.",
|
loginDescription: "شماره موبایل خود را وارد کنید تا با رمز عبور وارد شوید.",
|
||||||
loginCta: "ورود",
|
loginCta: "ورود",
|
||||||
createAccount: "ایجاد حساب",
|
createAccount: "ایجاد حساب",
|
||||||
haveNoAccount: "حساب ندارید؟",
|
haveNoAccount: "حساب ندارید؟",
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { useMemo } from "react"
|
|
||||||
import { Link, useNavigate } from "react-router-dom"
|
import { Link, useNavigate } from "react-router-dom"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
|
||||||
@@ -8,7 +7,6 @@ import { Input } from "../../components/ui/input"
|
|||||||
import { useAuthFlow } from "../../context/AuthFlowContext"
|
import { useAuthFlow } from "../../context/AuthFlowContext"
|
||||||
import { useTranslation } from "../../hooks/useTranslation"
|
import { useTranslation } from "../../hooks/useTranslation"
|
||||||
import { AuthPanel } from "./AuthPanel"
|
import { AuthPanel } from "./AuthPanel"
|
||||||
import { formatCooldown } from "./utils"
|
|
||||||
|
|
||||||
const GoogleIcon = () => (
|
const GoogleIcon = () => (
|
||||||
<svg aria-hidden="true" className="h-5 w-5" viewBox="0 0 24 24">
|
<svg aria-hidden="true" className="h-5 w-5" viewBox="0 0 24 24">
|
||||||
@@ -34,24 +32,8 @@ const GoogleIcon = () => (
|
|||||||
export function LoginMobilePage() {
|
export function LoginMobilePage() {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { t, lang } = useTranslation()
|
const { t, lang } = useTranslation()
|
||||||
const { state, setMobile, markOtpSendPending, clearOtpDelivery, resetFlow } = useAuthFlow()
|
const { state, setMobile, clearOtpDelivery, resetFlow } = useAuthFlow()
|
||||||
const isRtl = lang === "fa"
|
const isRtl = lang === "fa"
|
||||||
const alert = useMemo(() => {
|
|
||||||
if (state.cooldowns.loginOtpSend <= 0) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const formatted = formatCooldown(state.cooldowns.loginOtpSend, isRtl)
|
|
||||||
return {
|
|
||||||
title: t.login.throttle.title,
|
|
||||||
description: t.login.throttle.otpSendMessage(formatted),
|
|
||||||
}
|
|
||||||
}, [isRtl, state.cooldowns.loginOtpSend, t.login.throttle])
|
|
||||||
|
|
||||||
const cooldownLabel =
|
|
||||||
state.cooldowns.loginOtpSend > 0
|
|
||||||
? t.login.throttle.countdownLabel(formatCooldown(state.cooldowns.loginOtpSend, isRtl))
|
|
||||||
: null
|
|
||||||
|
|
||||||
const handleLogin = async () => {
|
const handleLogin = async () => {
|
||||||
if (!state.login.mobile) {
|
if (!state.login.mobile) {
|
||||||
@@ -61,15 +43,13 @@ export function LoginMobilePage() {
|
|||||||
|
|
||||||
resetFlow("forgotPassword")
|
resetFlow("forgotPassword")
|
||||||
clearOtpDelivery("login")
|
clearOtpDelivery("login")
|
||||||
markOtpSendPending("login")
|
navigate("/auth/login/password")
|
||||||
navigate("/auth/login/verify")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuthPanel
|
<AuthPanel
|
||||||
title={t.login.loginTitle}
|
title={t.login.loginTitle}
|
||||||
description={t.login.loginDescription}
|
description={t.login.loginDescription}
|
||||||
alert={alert}
|
|
||||||
>
|
>
|
||||||
<div className="grid gap-4">
|
<div className="grid gap-4">
|
||||||
<Input
|
<Input
|
||||||
@@ -85,10 +65,9 @@ export function LoginMobilePage() {
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
onClick={handleLogin}
|
onClick={handleLogin}
|
||||||
disabled={state.cooldowns.loginOtpSend > 0}
|
|
||||||
className="h-11 w-full"
|
className="h-11 w-full"
|
||||||
>
|
>
|
||||||
{cooldownLabel || t.login.loginCta}
|
{t.login.continueWithPassword}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
|
|||||||
@@ -14,7 +14,16 @@ import { completeAuthentication, formatCooldown, getApiErrorMessage, handleThrot
|
|||||||
export function LoginPasswordPage() {
|
export function LoginPasswordPage() {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { t, lang } = useTranslation()
|
const { t, lang } = useTranslation()
|
||||||
const { state, setMobile, clearCooldown, setCooldown, setCode, resetFlow } = useAuthFlow()
|
const {
|
||||||
|
state,
|
||||||
|
setMobile,
|
||||||
|
clearCooldown,
|
||||||
|
setCooldown,
|
||||||
|
setCode,
|
||||||
|
clearOtpDelivery,
|
||||||
|
markOtpSendPending,
|
||||||
|
resetFlow,
|
||||||
|
} = useAuthFlow()
|
||||||
const isRtl = lang === "fa"
|
const isRtl = lang === "fa"
|
||||||
const [password, setPassword] = useState("")
|
const [password, setPassword] = useState("")
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
@@ -95,7 +104,16 @@ export function LoginPasswordPage() {
|
|||||||
{cooldownLabel || t.login.signIn}
|
{cooldownLabel || t.login.signIn}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button type="button" variant="outline" className="h-11 w-full" onClick={() => navigate("/auth/login/verify")}>
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
className="h-11 w-full"
|
||||||
|
onClick={() => {
|
||||||
|
clearOtpDelivery("login")
|
||||||
|
markOtpSendPending("login")
|
||||||
|
navigate("/auth/login/verify")
|
||||||
|
}}
|
||||||
|
>
|
||||||
{t.login.useOtpInstead}
|
{t.login.useOtpInstead}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user