Fixed build ESLint warnings.

This commit is contained in:
Andrés 2025-10-22 01:53:30 -05:00
parent 26045484f6
commit 7025442d28
6 changed files with 40 additions and 20 deletions

View File

@ -1,5 +1,5 @@
import { POST, GET } from "./config"; // import { POST, GET } from "./config";
import { AUTH_ENDPOINTS, getAuthHeaders } from "./config"; // import { AUTH_ENDPOINTS, getAuthHeaders } from "./config";
// Simulated delay for realistic API behavior // Simulated delay for realistic API behavior
const simulateDelay = (ms = 800) => const simulateDelay = (ms = 800) =>
@ -10,7 +10,7 @@ const MOCK_USER = {
id: 1, id: 1,
username: "demo@craftandharvest.com", username: "demo@craftandharvest.com",
email: "demo@craftandharvest.com", email: "demo@craftandharvest.com",
name: "Taylor", // name: 'Taylor', // Unused for now
role: "admin", role: "admin",
}; };
@ -51,7 +51,7 @@ const login = async ({ username, password }) => {
}; };
// Logout // Logout
const logout = async (token) => { const logout = async () => {
await simulateDelay(300); await simulateDelay(300);
return { return {
@ -68,6 +68,8 @@ const logout = async (token) => {
const register = async ({ email, password }) => { const register = async ({ email, password }) => {
await simulateDelay(); await simulateDelay();
console.log({ email, password });
const token = "mock_jwt_token_" + Date.now(); const token = "mock_jwt_token_" + Date.now();
return { return {
@ -110,6 +112,8 @@ const me = async (token) => {
const refresh = async (refreshToken) => { const refresh = async (refreshToken) => {
await simulateDelay(300); await simulateDelay(300);
console.log({ refreshToken });
return { return {
data: { data: {
token: "mock_jwt_token_" + Date.now(), token: "mock_jwt_token_" + Date.now(),
@ -169,6 +173,8 @@ const resetPassword = async ({ token, password }) => {
const changePassword = async ({ currentPassword, newPassword, token }) => { const changePassword = async ({ currentPassword, newPassword, token }) => {
await simulateDelay(); await simulateDelay();
console.log({ currentPassword, newPassword, token });
if (currentPassword === "demo123" && newPassword.length >= 6) { if (currentPassword === "demo123" && newPassword.length >= 6) {
return { return {
data: { data: {

View File

@ -7,6 +7,9 @@ export const AUTH_ENDPOINTS = {
REGISTER: "/auth/register", REGISTER: "/auth/register",
REFRESH: "/auth/refresh", REFRESH: "/auth/refresh",
ME: "/auth/me", ME: "/auth/me",
REQUEST_PASSWORD_RESET: "/auth/request-password-reset",
RESET_PASSWORD: "/auth/reset-password",
CHANGE_PASSWORD: "/auth/change-password",
}; };
// Auth-specific headers // Auth-specific headers

View File

@ -24,12 +24,20 @@ export default function LoginPage() {
if (ok && data) { if (ok && data) {
setSuccess(true); setSuccess(true);
localStorage.setItem("token", (data as any).token); const token =
localStorage.setItem("user", JSON.stringify((data as any).user)); data && typeof data === "object" && "token" in data ? data.token : "";
const user =
data && typeof data === "object" && "user" in data ? data.user : {};
localStorage.setItem("token", token as string);
localStorage.setItem("user", JSON.stringify(user));
console.log("Login successful:", data); console.log("Login successful:", data);
} else { } else {
setError((data as any)?.message || "Login failed. Please try again."); const errorMessage =
data && typeof data === "object" && "message" in data
? (data.message as string)
: "Login failed. Please try again.";
setError(errorMessage);
} }
}, },
[username, password] [username, password]
@ -134,14 +142,14 @@ export default function LoginPage() {
<div className="mt-6 text-center space-y-3"> <div className="mt-6 text-center space-y-3">
<a <a
href="#" href="/request-password-reset"
className="text-sm hover:underline block" className="text-sm hover:underline block"
style={{ color: "var(--foreground)" }} style={{ color: "var(--foreground)" }}
> >
Forgot password? Forgot password?
</a> </a>
<p className="text-sm" style={{ color: "var(--foreground)" }}> <p className="text-sm" style={{ color: "var(--foreground)" }}>
Don't have an account?{" "} Don&apos;t have an account?{" "}
<Link <Link
href="/sign-up" href="/sign-up"
className="font-medium hover:underline" className="font-medium hover:underline"

View File

@ -46,7 +46,7 @@ export default function RequestPasswordResetPage() {
setSuccess(true); setSuccess(true);
} else { } else {
setError( setError(
(data as any)?.message || (data?.message as string) ||
"Failed to send reset email. Please try again." "Failed to send reset email. Please try again."
); );
} }
@ -124,15 +124,16 @@ export default function RequestPasswordResetPage() {
<div className="p-4 rounded bg-green-50 border border-green-200 text-green-700"> <div className="p-4 rounded bg-green-50 border border-green-200 text-green-700">
<p className="font-medium mb-1">Email sent!</p> <p className="font-medium mb-1">Email sent!</p>
<p className="text-sm"> <p className="text-sm">
We've sent a password reset link to <strong>{email}</strong>. We&apos;ve sent a password reset link to{" "}
Please check your inbox and follow the instructions. <strong>{email}</strong>. Please check your inbox and follow
the instructions.
</p> </p>
</div> </div>
<p <p
className="text-sm text-center" className="text-sm text-center"
style={{ color: "var(--foreground)" }} style={{ color: "var(--foreground)" }}
> >
Didn't receive the email? Check your spam folder or{" "} Didn&apos;t receive the email? Check your spam folder or{" "}
<button <button
onClick={() => { onClick={() => {
setSuccess(false); setSuccess(false);

View File

@ -60,7 +60,7 @@ export default function ResetPasswordPage() {
setSuccess(true); setSuccess(true);
} else { } else {
setError( setError(
(data as any)?.message || (data?.message as string) ||
"Failed to reset password. Please try again." "Failed to reset password. Please try again."
); );
} }

View File

@ -4,7 +4,7 @@ import { useState, useCallback, useEffect } from "react";
import { AUTH } from "@/api/auth/api"; import { AUTH } from "@/api/auth/api";
import Link from "next/link"; import Link from "next/link";
export default function RegisterPage() { export default function SignUpPage() {
const [email, setEmail] = useState(""); const [email, setEmail] = useState("");
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const [confirmPassword, setConfirmPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState("");
@ -70,15 +70,17 @@ export default function RegisterPage() {
if (ok && data) { if (ok && data) {
setSuccess(true); setSuccess(true);
// Store token in localStorage // Store token in localStorage
localStorage.setItem("token", (data as any).token); localStorage.setItem("token", data.token as string);
localStorage.setItem("user", JSON.stringify((data as any).user)); localStorage.setItem("user", JSON.stringify(data.user));
// Redirect or update app state here // Redirect or update app state here
console.log("Registration successful:", data); console.log("Registration successful:", data);
} else { } else {
setError( const errorMessage =
(data as any)?.message || "Registration failed. Please try again." data && typeof data === "object" && "message" in data
); ? (data.message as string)
: "Registration failed. Please try again.";
setError(errorMessage);
} }
}, },
[email, password, emailError, passwordError] [email, password, emailError, passwordError]