ref: change auth setting in Login Screen
This commit is contained in:
parent
9d31ea245c
commit
12c90ff120
26 changed files with 1149 additions and 99 deletions
|
|
@ -3,24 +3,28 @@ import { Box, Typography } from "@mui/material"
|
|||
import { useRouter } from "next/navigation"
|
||||
import React, { useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { auth } from "@app/account/controller/AuthController"
|
||||
import Button from "@atoms/Button"
|
||||
import Input from "@atoms/Input"
|
||||
import Label from "@atoms/Label"
|
||||
import {Login} from "@package/config/api/Admin/auth/Login/page"
|
||||
|
||||
const LoginForm: React.FC = () => {
|
||||
const [username, setUsername] = useState("")
|
||||
const [email, setEmail] = useState("")
|
||||
const [password, setPassword] = useState("")
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const router = useRouter()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const handleLogin = async () => {
|
||||
const token = await auth(username, password)
|
||||
if (token) {
|
||||
router.push("/home")
|
||||
} else {
|
||||
setError( t("msj_Incorrect_credentials_try_again."))
|
||||
try {
|
||||
const response = await Login(email, password)
|
||||
if (response.correct) {
|
||||
router.push("/selfcheckout/precheckout")
|
||||
} else {
|
||||
setError(response.message || t("msj_Incorrect_credentials_try_again"))
|
||||
}
|
||||
} catch (err) {
|
||||
setError(t("msj_Incorrect_credentials_try_again"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -34,13 +38,13 @@ const LoginForm: React.FC = () => {
|
|||
sx={{ display: "flex", flexDirection: "column", gap: 3, width: "100%" }}
|
||||
>
|
||||
<Box>
|
||||
<Label htmlFor={t("lbl_username")} text={t("lbl_username")} />
|
||||
<Label htmlFor={t("lbl_email")} text={t("lbl_email")} />
|
||||
<Input
|
||||
type="text"
|
||||
placeholder={t("msj_enter_your_username")}
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
autocomplete="username"
|
||||
type="email"
|
||||
placeholder={t("msj_enter_your_email")}
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
autocomplete="email"
|
||||
/>
|
||||
</Box>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue