fix(loginform): removed the console log that was left by accident
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
import {useSessionStore} from "../../lib/store/sessionStore";
|
import { useSessionStore } from "../../lib/store/sessionStore";
|
||||||
import {LstCard} from "../extendedUI/LstCard";
|
import { LstCard } from "../extendedUI/LstCard";
|
||||||
import {CardHeader} from "../ui/card";
|
import { CardHeader } from "../ui/card";
|
||||||
import {toast} from "sonner";
|
import { toast } from "sonner";
|
||||||
import {z} from "zod";
|
import { z } from "zod";
|
||||||
import {useRouter} from "@tanstack/react-router";
|
import { useRouter } from "@tanstack/react-router";
|
||||||
import {Controller, useForm} from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import {zodResolver} from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import {Label} from "../ui/label";
|
import { Label } from "../ui/label";
|
||||||
import {Input} from "../ui/input";
|
import { Input } from "../ui/input";
|
||||||
import {Checkbox} from "../ui/checkbox";
|
import { Checkbox } from "../ui/checkbox";
|
||||||
import {Button} from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
|
|
||||||
const FormSchema = z.object({
|
const FormSchema = z.object({
|
||||||
username: z.string().min(1, "You must enter a valid username"),
|
username: z.string().min(1, "You must enter a valid username"),
|
||||||
@@ -18,7 +18,7 @@ const FormSchema = z.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const LoginForm = () => {
|
const LoginForm = () => {
|
||||||
const {setSession} = useSessionStore();
|
const { setSession } = useSessionStore();
|
||||||
const rememeberMe = localStorage.getItem("rememberMe") === "true";
|
const rememeberMe = localStorage.getItem("rememberMe") === "true";
|
||||||
const username = localStorage.getItem("username") || "";
|
const username = localStorage.getItem("username") || "";
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -26,7 +26,7 @@ const LoginForm = () => {
|
|||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
control,
|
control,
|
||||||
formState: {errors},
|
formState: { errors },
|
||||||
} = useForm<z.infer<typeof FormSchema>>({
|
} = useForm<z.infer<typeof FormSchema>>({
|
||||||
resolver: zodResolver(FormSchema),
|
resolver: zodResolver(FormSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
@@ -54,7 +54,10 @@ const LoginForm = () => {
|
|||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({username: value.username, password: value.password}),
|
body: JSON.stringify({
|
||||||
|
username: value.username,
|
||||||
|
password: value.password,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
@@ -63,18 +66,18 @@ const LoginForm = () => {
|
|||||||
// localStorage.setItem("auth_token", data.data.token);
|
// localStorage.setItem("auth_token", data.data.token);
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
const prod = btoa(`${value.username.toLowerCase()}:${value.password}`);
|
const prod = btoa(`${value.username.toLowerCase()}:${value.password}`);
|
||||||
const prodUser = {...data.user, prod: prod};
|
const prodUser = { ...data.user, prod: prod };
|
||||||
|
|
||||||
setSession(prodUser, data.token);
|
setSession(prodUser, data.token);
|
||||||
toast.success(`You are logged in as ${data.user.username}`);
|
toast.success(`You are logged in as ${data.user.username}`);
|
||||||
router.navigate({to: "/"});
|
router.navigate({ to: "/" });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
toast.error(`${data.message}`);
|
toast.error(`${data.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(data);
|
//console.log(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast.error("Invalid credentials");
|
toast.error("Invalid credentials");
|
||||||
}
|
}
|
||||||
@@ -100,7 +103,11 @@ const LoginForm = () => {
|
|||||||
className={errors.username ? "border-red-500" : ""}
|
className={errors.username ? "border-red-500" : ""}
|
||||||
aria-invalid={!!errors.username}
|
aria-invalid={!!errors.username}
|
||||||
/>
|
/>
|
||||||
{errors.username && <p className="text-red-500 text-sm mt-1">{errors.username.message}</p>}
|
{errors.username && (
|
||||||
|
<p className="text-red-500 text-sm mt-1">
|
||||||
|
{errors.username.message}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<>
|
<>
|
||||||
@@ -113,13 +120,17 @@ const LoginForm = () => {
|
|||||||
className={errors.password ? "border-red-500" : ""}
|
className={errors.password ? "border-red-500" : ""}
|
||||||
aria-invalid={!!errors.password}
|
aria-invalid={!!errors.password}
|
||||||
/>
|
/>
|
||||||
{errors.password && <p className="text-red-500 text-sm mt-1">{errors.password.message}</p>}
|
{errors.password && (
|
||||||
|
<p className="text-red-500 text-sm mt-1">
|
||||||
|
{errors.password.message}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between pt-2">
|
<div className="flex justify-between pt-2">
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
<Controller
|
<Controller
|
||||||
render={({field}) => (
|
render={({ field }) => (
|
||||||
<>
|
<>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
id="remember"
|
id="remember"
|
||||||
|
|||||||
Reference in New Issue
Block a user