Skip to content

Commit bd5d557

Browse files
NodeDiverclaude
andcommitted
Week 1 Task 4: Replace console.logs with centralized logger utility
- Create logger utility (src/lib/logger.ts) with structured logging - Add debug, info, warn, error methods with context objects - Support for external logging services (Sentry, etc.) in future - Replace all 55+ console.* statements across src/ with logger - Update middleware, auth, email, rate-limit with logger - Update all API routes (auth, communities, payments) with logger - Update all page components (sign-in, sign-up, discover, etc.) - Update client components (CommunitiesGrid, LanguageToggle) - Logger only shows debug messages in development mode 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c14743f commit bd5d557

File tree

32 files changed

+714
-495
lines changed

32 files changed

+714
-495
lines changed
Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,57 @@
1-
'use client'
1+
"use client";
22

3-
import { useState } from 'react'
4-
import { useTranslations, useLocale } from 'next-intl'
5-
import { Button } from '@/components/ui/button'
6-
import { Input } from '@/components/ui/input'
7-
import { Label } from '@/components/ui/label'
8-
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
9-
import Link from 'next/link'
3+
import { useState } from "react";
4+
import { useTranslations, useLocale } from "next-intl";
5+
import { Button } from "@/components/ui/button";
6+
import { Input } from "@/components/ui/input";
7+
import { Label } from "@/components/ui/label";
8+
import {
9+
Card,
10+
CardContent,
11+
CardDescription,
12+
CardHeader,
13+
CardTitle,
14+
} from "@/components/ui/card";
15+
import Link from "next/link";
16+
import { logger } from "@/lib/logger";
1017

1118
export default function ForgotPasswordPage() {
12-
const [email, setEmail] = useState('')
13-
const [isLoading, setIsLoading] = useState(false)
14-
const [success, setSuccess] = useState(false)
15-
const [error, setError] = useState('')
16-
const t = useTranslations()
17-
const locale = useLocale()
19+
const [email, setEmail] = useState("");
20+
const [isLoading, setIsLoading] = useState(false);
21+
const [success, setSuccess] = useState(false);
22+
const [error, setError] = useState("");
23+
const t = useTranslations();
24+
const locale = useLocale();
1825

1926
const handleSubmit = async (e: React.FormEvent) => {
20-
e.preventDefault()
21-
setError('')
22-
setIsLoading(true)
27+
e.preventDefault();
28+
setError("");
29+
setIsLoading(true);
2330

2431
try {
25-
const response = await fetch('/api/auth/forgot-password', {
26-
method: 'POST',
32+
const response = await fetch("/api/auth/forgot-password", {
33+
method: "POST",
2734
headers: {
28-
'Content-Type': 'application/json',
29-
'Accept-Language': locale,
35+
"Content-Type": "application/json",
36+
"Accept-Language": locale,
3037
},
3138
body: JSON.stringify({ email }),
32-
})
39+
});
3340

34-
const data = await response.json()
41+
const data = await response.json();
3542

3643
if (response.ok) {
37-
setSuccess(true)
44+
setSuccess(true);
3845
} else {
39-
setError(data.error || 'Something went wrong')
46+
setError(data.error || "Something went wrong");
4047
}
4148
} catch (error) {
42-
console.error('Forgot password error:', error)
43-
setError('Network error. Please try again.')
49+
logger.error("Forgot password error:", error);
50+
setError("Network error. Please try again.");
4451
} finally {
45-
setIsLoading(false)
52+
setIsLoading(false);
4653
}
47-
}
54+
};
4855

4956
if (success) {
5057
return (
@@ -53,22 +60,22 @@ export default function ForgotPasswordPage() {
5360
<CardHeader>
5461
<CardTitle>Check Your Email</CardTitle>
5562
<CardDescription>
56-
If an account exists with that email, we've sent a password reset link.
63+
If an account exists with that email, we've sent a password reset
64+
link.
5765
</CardDescription>
5866
</CardHeader>
5967
<CardContent>
6068
<p className="text-sm text-gray-600 dark:text-gray-400 mb-4">
61-
The link will expire in 1 hour. If you don't see the email, check your spam folder.
69+
The link will expire in 1 hour. If you don't see the email, check
70+
your spam folder.
6271
</p>
6372
<Link href={`/${locale}/sign-in`}>
64-
<Button className="w-full">
65-
Back to Sign In
66-
</Button>
73+
<Button className="w-full">Back to Sign In</Button>
6774
</Link>
6875
</CardContent>
6976
</Card>
7077
</div>
71-
)
78+
);
7279
}
7380

7481
return (
@@ -77,7 +84,8 @@ export default function ForgotPasswordPage() {
7784
<CardHeader>
7885
<CardTitle>Forgot Password?</CardTitle>
7986
<CardDescription>
80-
Enter your email address and we'll send you a link to reset your password
87+
Enter your email address and we'll send you a link to reset your
88+
password
8189
</CardDescription>
8290
</CardHeader>
8391
<CardContent>
@@ -88,7 +96,7 @@ export default function ForgotPasswordPage() {
8896
</div>
8997
)}
9098
<div>
91-
<Label htmlFor="email">{t('forms.email')}</Label>
99+
<Label htmlFor="email">{t("forms.email")}</Label>
92100
<Input
93101
id="email"
94102
type="email"
@@ -100,22 +108,28 @@ export default function ForgotPasswordPage() {
100108
/>
101109
</div>
102110
<Button type="submit" className="w-full" disabled={isLoading}>
103-
{isLoading ? 'Sending...' : 'Send Reset Link'}
111+
{isLoading ? "Sending..." : "Send Reset Link"}
104112
</Button>
105113
</form>
106114
<div className="mt-6 text-center space-y-2">
107115
<p className="text-sm text-gray-600 dark:text-gray-400">
108-
Remember your password?{' '}
109-
<Link href={`/${locale}/sign-in`} className="text-blue-600 hover:underline font-medium">
116+
Remember your password?{" "}
117+
<Link
118+
href={`/${locale}/sign-in`}
119+
className="text-blue-600 hover:underline font-medium"
120+
>
110121
Sign in here
111122
</Link>
112123
</p>
113-
<Link href={`/${locale}`} className="text-sm text-gray-500 hover:underline block">
124+
<Link
125+
href={`/${locale}`}
126+
className="text-sm text-gray-500 hover:underline block"
127+
>
114128
Back to Home
115129
</Link>
116130
</div>
117131
</CardContent>
118132
</Card>
119133
</div>
120-
)
134+
);
121135
}

src/app/[locale]/(auth)/reset-password/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
CardTitle,
1515
} from "@/components/ui/card";
1616
import Link from "next/link";
17+
import { logger } from "@/lib/logger";
1718

1819
function ResetPasswordForm() {
1920
const [password, setPassword] = useState("");
@@ -72,7 +73,7 @@ function ResetPasswordForm() {
7273
setError(data.error || "Failed to reset password");
7374
}
7475
} catch (error) {
75-
console.error("Reset password error:", error);
76+
logger.error("Reset password error:", error);
7677
setError("Network error. Please try again.");
7778
} finally {
7879
setIsLoading(false);
Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,52 @@
1-
'use client'
1+
"use client";
22

3-
import { useState } from 'react'
4-
import { signIn } from 'next-auth/react'
5-
import { useRouter } from 'next/navigation'
6-
import { useTranslations, useLocale } from 'next-intl'
7-
import { Button } from '@/components/ui/button'
8-
import { Input } from '@/components/ui/input'
9-
import { Label } from '@/components/ui/label'
10-
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
11-
import Link from 'next/link'
3+
import { useState } from "react";
4+
import { signIn } from "next-auth/react";
5+
import { useRouter } from "next/navigation";
6+
import { useTranslations, useLocale } from "next-intl";
7+
import { Button } from "@/components/ui/button";
8+
import { Input } from "@/components/ui/input";
9+
import { Label } from "@/components/ui/label";
10+
import {
11+
Card,
12+
CardContent,
13+
CardDescription,
14+
CardHeader,
15+
CardTitle,
16+
} from "@/components/ui/card";
17+
import Link from "next/link";
18+
import { logger } from "@/lib/logger";
1219

1320
export default function SignInPage() {
14-
const [username, setUsername] = useState('')
15-
const [password, setPassword] = useState('')
16-
const [isLoading, setIsLoading] = useState(false)
17-
const router = useRouter()
18-
const t = useTranslations()
19-
const locale = useLocale()
21+
const [username, setUsername] = useState("");
22+
const [password, setPassword] = useState("");
23+
const [isLoading, setIsLoading] = useState(false);
24+
const router = useRouter();
25+
const t = useTranslations();
26+
const locale = useLocale();
2027

2128
const handleSubmit = async (e: React.FormEvent) => {
22-
e.preventDefault()
23-
setIsLoading(true)
29+
e.preventDefault();
30+
setIsLoading(true);
2431

2532
try {
26-
const result = await signIn('credentials', {
33+
const result = await signIn("credentials", {
2734
username,
2835
password,
2936
redirect: false,
30-
})
37+
});
3138

3239
if (result?.ok) {
33-
router.push(`/${locale}/discover`)
40+
router.push(`/${locale}/discover`);
3441
} else {
35-
console.error('Sign in failed')
42+
logger.error("Sign in failed");
3643
}
3744
} catch (error) {
38-
console.error('Sign in error:', error)
45+
logger.error("Sign in error:", error);
3946
} finally {
40-
setIsLoading(false)
47+
setIsLoading(false);
4148
}
42-
}
49+
};
4350

4451
return (
4552
<div className="min-h-screen flex items-center justify-center bg-gray-50">
@@ -53,7 +60,7 @@ export default function SignInPage() {
5360
<CardContent>
5461
<form onSubmit={handleSubmit} className="space-y-4">
5562
<div>
56-
<Label htmlFor="username">{t('forms.username')}</Label>
63+
<Label htmlFor="username">{t("forms.username")}</Label>
5764
<Input
5865
id="username"
5966
type="text"
@@ -75,16 +82,22 @@ export default function SignInPage() {
7582
/>
7683
</div>
7784
<Button type="submit" className="w-full" disabled={isLoading}>
78-
{isLoading ? 'Signing in...' : 'Sign In'}
85+
{isLoading ? "Signing in..." : "Sign In"}
7986
</Button>
8087
</form>
8188
<div className="mt-6 text-center space-y-2">
82-
<Link href={`/${locale}/forgot-password`} className="text-sm text-blue-600 hover:underline block">
89+
<Link
90+
href={`/${locale}/forgot-password`}
91+
className="text-sm text-blue-600 hover:underline block"
92+
>
8393
Forgot password?
8494
</Link>
8595
<p className="text-sm text-gray-600 dark:text-gray-400">
86-
Don't have an account?{' '}
87-
<Link href={`/${locale}/sign-up`} className="text-blue-600 hover:underline font-medium">
96+
Don't have an account?{" "}
97+
<Link
98+
href={`/${locale}/sign-up`}
99+
className="text-blue-600 hover:underline font-medium"
100+
>
88101
Create a new account here
89102
</Link>
90103
</p>
@@ -95,5 +108,5 @@ export default function SignInPage() {
95108
</CardContent>
96109
</Card>
97110
</div>
98-
)
111+
);
99112
}

0 commit comments

Comments
 (0)