Compare commits
2 Commits
26045484f6
...
d24f484bb2
| Author | SHA1 | Date |
|---|---|---|
|
|
d24f484bb2 | |
|
|
7025442d28 |
|
|
@ -1,5 +1,5 @@
|
|||
import { POST, GET } from "./config";
|
||||
import { AUTH_ENDPOINTS, getAuthHeaders } from "./config";
|
||||
// import { POST, GET } from "./config";
|
||||
// import { AUTH_ENDPOINTS, getAuthHeaders } from "./config";
|
||||
|
||||
// Simulated delay for realistic API behavior
|
||||
const simulateDelay = (ms = 800) =>
|
||||
|
|
@ -10,7 +10,7 @@ const MOCK_USER = {
|
|||
id: 1,
|
||||
username: "demo@craftandharvest.com",
|
||||
email: "demo@craftandharvest.com",
|
||||
name: "Taylor",
|
||||
// name: 'Taylor', // Unused for now
|
||||
role: "admin",
|
||||
};
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ const login = async ({ username, password }) => {
|
|||
};
|
||||
|
||||
// Logout
|
||||
const logout = async (token) => {
|
||||
const logout = async () => {
|
||||
await simulateDelay(300);
|
||||
|
||||
return {
|
||||
|
|
@ -68,6 +68,8 @@ const logout = async (token) => {
|
|||
const register = async ({ email, password }) => {
|
||||
await simulateDelay();
|
||||
|
||||
console.log({ email, password });
|
||||
|
||||
const token = "mock_jwt_token_" + Date.now();
|
||||
|
||||
return {
|
||||
|
|
@ -110,6 +112,8 @@ const me = async (token) => {
|
|||
const refresh = async (refreshToken) => {
|
||||
await simulateDelay(300);
|
||||
|
||||
console.log({ refreshToken });
|
||||
|
||||
return {
|
||||
data: {
|
||||
token: "mock_jwt_token_" + Date.now(),
|
||||
|
|
@ -169,6 +173,8 @@ const resetPassword = async ({ token, password }) => {
|
|||
const changePassword = async ({ currentPassword, newPassword, token }) => {
|
||||
await simulateDelay();
|
||||
|
||||
console.log({ currentPassword, newPassword, token });
|
||||
|
||||
if (currentPassword === "demo123" && newPassword.length >= 6) {
|
||||
return {
|
||||
data: {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ export const AUTH_ENDPOINTS = {
|
|||
REGISTER: "/auth/register",
|
||||
REFRESH: "/auth/refresh",
|
||||
ME: "/auth/me",
|
||||
REQUEST_PASSWORD_RESET: "/auth/request-password-reset",
|
||||
RESET_PASSWORD: "/auth/reset-password",
|
||||
CHANGE_PASSWORD: "/auth/change-password",
|
||||
};
|
||||
|
||||
// Auth-specific headers
|
||||
|
|
|
|||
|
|
@ -24,12 +24,20 @@ export default function LoginPage() {
|
|||
|
||||
if (ok && data) {
|
||||
setSuccess(true);
|
||||
localStorage.setItem("token", (data as any).token);
|
||||
localStorage.setItem("user", JSON.stringify((data as any).user));
|
||||
const token =
|
||||
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);
|
||||
} 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]
|
||||
|
|
@ -134,14 +142,14 @@ export default function LoginPage() {
|
|||
|
||||
<div className="mt-6 text-center space-y-3">
|
||||
<a
|
||||
href="#"
|
||||
href="/request-password-reset"
|
||||
className="text-sm hover:underline block"
|
||||
style={{ color: "var(--foreground)" }}
|
||||
>
|
||||
Forgot password?
|
||||
</a>
|
||||
<p className="text-sm" style={{ color: "var(--foreground)" }}>
|
||||
Don't have an account?{" "}
|
||||
Don't have an account?{" "}
|
||||
<Link
|
||||
href="/sign-up"
|
||||
className="font-medium hover:underline"
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ export default function RequestPasswordResetPage() {
|
|||
setSuccess(true);
|
||||
} else {
|
||||
setError(
|
||||
(data as any)?.message ||
|
||||
(data?.message as string) ||
|
||||
"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">
|
||||
<p className="font-medium mb-1">Email sent!</p>
|
||||
<p className="text-sm">
|
||||
We've sent a password reset link to <strong>{email}</strong>.
|
||||
Please check your inbox and follow the instructions.
|
||||
We've sent a password reset link to{" "}
|
||||
<strong>{email}</strong>. Please check your inbox and follow
|
||||
the instructions.
|
||||
</p>
|
||||
</div>
|
||||
<p
|
||||
className="text-sm text-center"
|
||||
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
|
||||
onClick={() => {
|
||||
setSuccess(false);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
"use client";
|
||||
|
||||
import { useState, useCallback, useEffect } from "react";
|
||||
import { useState, useCallback, useEffect, Suspense } from "react";
|
||||
import { AUTH } from "@/api/auth/api";
|
||||
import Link from "next/link";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
|
||||
export default function ResetPasswordPage() {
|
||||
function ResetPasswordForm() {
|
||||
const searchParams = useSearchParams();
|
||||
const token = searchParams.get("token");
|
||||
|
||||
|
|
@ -59,10 +59,11 @@ export default function ResetPasswordPage() {
|
|||
if (ok && data) {
|
||||
setSuccess(true);
|
||||
} else {
|
||||
setError(
|
||||
(data as any)?.message ||
|
||||
"Failed to reset password. Please try again."
|
||||
);
|
||||
const errorMessage =
|
||||
data && typeof data === "object" && "message" in data
|
||||
? (data.message as string)
|
||||
: "Failed to reset password. Please try again.";
|
||||
setError(errorMessage);
|
||||
}
|
||||
},
|
||||
[token, password, passwordError]
|
||||
|
|
@ -228,3 +229,19 @@ export default function ResetPasswordPage() {
|
|||
</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 Link from "next/link";
|
||||
|
||||
export default function RegisterPage() {
|
||||
export default function SignUpPage() {
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [confirmPassword, setConfirmPassword] = useState("");
|
||||
|
|
@ -70,15 +70,17 @@ export default function RegisterPage() {
|
|||
if (ok && data) {
|
||||
setSuccess(true);
|
||||
// Store token in localStorage
|
||||
localStorage.setItem("token", (data as any).token);
|
||||
localStorage.setItem("user", JSON.stringify((data as any).user));
|
||||
localStorage.setItem("token", data.token as string);
|
||||
localStorage.setItem("user", JSON.stringify(data.user));
|
||||
|
||||
// Redirect or update app state here
|
||||
console.log("Registration successful:", data);
|
||||
} else {
|
||||
setError(
|
||||
(data as any)?.message || "Registration failed. Please try again."
|
||||
);
|
||||
const errorMessage =
|
||||
data && typeof data === "object" && "message" in data
|
||||
? (data.message as string)
|
||||
: "Registration failed. Please try again.";
|
||||
setError(errorMessage);
|
||||
}
|
||||
},
|
||||
[email, password, emailError, passwordError]
|
||||
|
|
|
|||
Reference in New Issue