Compare commits
No commits in common. "d24f484bb26b11af17ca28919d69202037649d4f" and "26045484f68677c89de627ef05bc2de230e1b605" have entirely different histories.
d24f484bb2
...
26045484f6
|
|
@ -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', // Unused for now
|
name: "Taylor",
|
||||||
role: "admin",
|
role: "admin",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -51,7 +51,7 @@ const login = async ({ username, password }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Logout
|
// Logout
|
||||||
const logout = async () => {
|
const logout = async (token) => {
|
||||||
await simulateDelay(300);
|
await simulateDelay(300);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -68,8 +68,6 @@ const logout = async () => {
|
||||||
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 {
|
||||||
|
|
@ -112,8 +110,6 @@ 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(),
|
||||||
|
|
@ -173,8 +169,6 @@ 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: {
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,6 @@ 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
|
||||||
|
|
|
||||||
|
|
@ -24,20 +24,12 @@ export default function LoginPage() {
|
||||||
|
|
||||||
if (ok && data) {
|
if (ok && data) {
|
||||||
setSuccess(true);
|
setSuccess(true);
|
||||||
const token =
|
localStorage.setItem("token", (data as any).token);
|
||||||
data && typeof data === "object" && "token" in data ? data.token : "";
|
localStorage.setItem("user", JSON.stringify((data as any).user));
|
||||||
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 {
|
||||||
const errorMessage =
|
setError((data as any)?.message || "Login failed. Please try again.");
|
||||||
data && typeof data === "object" && "message" in data
|
|
||||||
? (data.message as string)
|
|
||||||
: "Login failed. Please try again.";
|
|
||||||
setError(errorMessage);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[username, password]
|
[username, password]
|
||||||
|
|
@ -142,14 +134,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="/request-password-reset"
|
href="#"
|
||||||
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't have an account?{" "}
|
||||||
<Link
|
<Link
|
||||||
href="/sign-up"
|
href="/sign-up"
|
||||||
className="font-medium hover:underline"
|
className="font-medium hover:underline"
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ export default function RequestPasswordResetPage() {
|
||||||
setSuccess(true);
|
setSuccess(true);
|
||||||
} else {
|
} else {
|
||||||
setError(
|
setError(
|
||||||
(data?.message as string) ||
|
(data as any)?.message ||
|
||||||
"Failed to send reset email. Please try again."
|
"Failed to send reset email. Please try again."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -124,16 +124,15 @@ 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{" "}
|
We've sent a password reset link to <strong>{email}</strong>.
|
||||||
<strong>{email}</strong>. Please check your inbox and follow
|
Please check your inbox and follow the instructions.
|
||||||
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't receive the email? Check your spam folder or{" "}
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSuccess(false);
|
setSuccess(false);
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState, useCallback, useEffect, Suspense } from "react";
|
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";
|
||||||
import { useSearchParams } from "next/navigation";
|
import { useSearchParams } from "next/navigation";
|
||||||
|
|
||||||
function ResetPasswordForm() {
|
export default function ResetPasswordPage() {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const token = searchParams.get("token");
|
const token = searchParams.get("token");
|
||||||
|
|
||||||
|
|
@ -59,11 +59,10 @@ function ResetPasswordForm() {
|
||||||
if (ok && data) {
|
if (ok && data) {
|
||||||
setSuccess(true);
|
setSuccess(true);
|
||||||
} else {
|
} else {
|
||||||
const errorMessage =
|
setError(
|
||||||
data && typeof data === "object" && "message" in data
|
(data as any)?.message ||
|
||||||
? (data.message as string)
|
"Failed to reset password. Please try again."
|
||||||
: "Failed to reset password. Please try again.";
|
);
|
||||||
setError(errorMessage);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[token, password, passwordError]
|
[token, password, passwordError]
|
||||||
|
|
@ -229,19 +228,3 @@ function ResetPasswordForm() {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ResetPasswordPage() {
|
|
||||||
return (
|
|
||||||
<Suspense
|
|
||||||
fallback={
|
|
||||||
<div className="min-h-screen flex items-center justify-center p-4">
|
|
||||||
<div className="text-center" style={{ color: "var(--foreground)" }}>
|
|
||||||
Loading...
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<ResetPasswordForm />
|
|
||||||
</Suspense>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -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 SignUpPage() {
|
export default function RegisterPage() {
|
||||||
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,17 +70,15 @@ export default function SignUpPage() {
|
||||||
if (ok && data) {
|
if (ok && data) {
|
||||||
setSuccess(true);
|
setSuccess(true);
|
||||||
// Store token in localStorage
|
// Store token in localStorage
|
||||||
localStorage.setItem("token", data.token as string);
|
localStorage.setItem("token", (data as any).token);
|
||||||
localStorage.setItem("user", JSON.stringify(data.user));
|
localStorage.setItem("user", JSON.stringify((data as any).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 {
|
||||||
const errorMessage =
|
setError(
|
||||||
data && typeof data === "object" && "message" in data
|
(data as any)?.message || "Registration failed. Please try again."
|
||||||
? (data.message as string)
|
);
|
||||||
: "Registration failed. Please try again.";
|
|
||||||
setError(errorMessage);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[email, password, emailError, passwordError]
|
[email, password, emailError, passwordError]
|
||||||
|
|
|
||||||
Reference in New Issue