Skip to content

Commit 1198d02

Browse files
committed
cleanup
1 parent f2eeaf8 commit 1198d02

File tree

8 files changed

+59
-92
lines changed

8 files changed

+59
-92
lines changed

src/app/(main)/_components/user-dropdown.tsx

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from "@/components/ui/dropdown-menu";
2323
import { logoutAction } from "@/lib/auth/actions";
2424
import { APP_TITLE } from "@/lib/constants";
25+
import Image from "next/image";
2526
import Link from "next/link";
2627
import { useState } from "react";
2728
import { toast } from "sonner";
@@ -42,14 +43,32 @@ export const UserDropdown = ({
4243
return (
4344
<DropdownMenu>
4445
<DropdownMenuTrigger className={className}>
45-
{/* eslint @next/next/no-img-element:off */}
46-
<img
47-
src={avatar ?? "https://source.boringavatars.com/marble/60/" + email}
48-
alt="Avatar"
49-
className="block h-8 w-8 rounded-full leading-none"
50-
width={64}
51-
height={64}
52-
></img>
46+
{avatar ? (
47+
<Image
48+
src={avatar}
49+
alt="Avatar"
50+
className="block h-8 w-8 rounded-full leading-none"
51+
width={64}
52+
height={64}
53+
/>
54+
) : (
55+
<div>
56+
<svg
57+
xmlns="http://www.w3.org/2000/svg"
58+
className="h-8 w-8 text-muted-foreground"
59+
fill="none"
60+
viewBox="0 0 24 24"
61+
stroke="currentColor"
62+
>
63+
<path
64+
strokeLinecap="round"
65+
strokeLinejoin="round"
66+
strokeWidth={2}
67+
d="M19 9l-7 7-7-7"
68+
/>
69+
</svg>
70+
</div>
71+
)}
5372
</DropdownMenuTrigger>
5473
<DropdownMenuContent align="end">
5574
<DropdownMenuLabel className="text-muted-foreground">{email}</DropdownMenuLabel>

src/lib/auth/actions.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { env } from "@/env";
44
import { EmailTemplate, sendMail } from "@/lib/email";
5-
import { loginSchema, resetPasswordSchema, signupSchema } from "@/lib/validators/auth";
65
import { redirect } from "next/navigation";
76
import { z } from "zod";
87
import { validateRequest } from ".";
@@ -11,6 +10,19 @@ import { Paths } from "../constants";
1110
import adapter from "./adapter";
1211
import utils from "./utils";
1312

13+
const loginSchema = z.object({
14+
email: z.string().email("Please enter a valid email"),
15+
password: z.string().min(1, "Please provide your password.").max(255),
16+
});
17+
const signupSchema = z.object({
18+
email: z.string().email("Please enter a valid email."),
19+
password: z.string().min(8, "Password is too short. Minimum 8 characters required.").max(255),
20+
});
21+
const resetPasswordSchema = z.object({
22+
token: z.string().min(1, "Invalid token"),
23+
password: z.string().min(8, "Password is too short").max(255),
24+
});
25+
1426
export const loginAction = validatedAction(loginSchema, async (_, input) => {
1527
const { email, password } = input;
1628
try {

src/lib/hooks/use-debounce.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/lib/logger.ts

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,42 @@ enum LogLevel {
99
ERROR = "ERROR",
1010
}
1111

12+
type LoggerParams = [string, Record<string, unknown>];
13+
1214
class Logger {
13-
private level: LogLevel;
1415
private logFilePath: string;
15-
16-
constructor(level: LogLevel = LogLevel.INFO, logFilePath = "application.log") {
17-
this.level = level;
16+
constructor(logFilePath = "application.log") {
1817
this.logFilePath = path.resolve(logFilePath);
1918
}
20-
2119
private getTimestamp(): string {
2220
return new Date().toISOString();
2321
}
24-
25-
private formatMessage(level: LogLevel, args: unknown[]): string {
26-
const message = args
27-
.map((arg) => (typeof arg === "object" ? JSON.stringify(arg) : arg))
28-
.join(" ");
29-
22+
private formatMessage(level: LogLevel, msg: string, args: Record<string, unknown>): string {
23+
const message = { timestamp: this.getTimestamp(), level, msg, ...args };
3024
if (env.NODE_ENV === "development") {
3125
console.log(message);
3226
}
33-
34-
return `[${this.getTimestamp()}] [${level}] ${message}`;
27+
return JSON.stringify(message);
3528
}
3629

37-
private log(level: LogLevel, ...args: unknown[]): void {
38-
if (this.shouldLog(level)) {
39-
const logMessage = this.formatMessage(level, args) + "\n";
40-
fs.appendFile(this.logFilePath, logMessage, (err) => {
41-
if (err) throw err;
42-
});
43-
}
30+
private log(level: LogLevel, msg: string, args: Record<string, unknown>): void {
31+
const logMessage = this.formatMessage(level, msg, args) + "\n";
32+
fs.appendFile(this.logFilePath, logMessage, (err) => {
33+
if (err) throw err;
34+
});
4435
}
45-
46-
private shouldLog(level: LogLevel): boolean {
47-
const levels = [LogLevel.DEBUG, LogLevel.INFO, LogLevel.WARN, LogLevel.ERROR];
48-
return levels.indexOf(level) >= levels.indexOf(this.level);
49-
}
50-
51-
debug(...args: unknown[]): void {
52-
this.log(LogLevel.DEBUG, ...args);
36+
debug(...args: LoggerParams) {
37+
if (env.NODE_ENV !== "production") this.log(LogLevel.DEBUG, ...args);
5338
}
54-
55-
info(...args: unknown[]): void {
39+
info(...args: LoggerParams) {
5640
this.log(LogLevel.INFO, ...args);
5741
}
58-
59-
warn(...args: unknown[]): void {
42+
warn(...args: LoggerParams) {
6043
this.log(LogLevel.WARN, ...args);
6144
}
62-
63-
error(...args: unknown[]): void {
45+
error(...args: LoggerParams) {
6446
this.log(LogLevel.ERROR, ...args);
6547
}
6648
}
6749

68-
export const logger = new Logger(env.NODE_ENV === "development" ? LogLevel.DEBUG : LogLevel.INFO);
50+
export const logger = new Logger();

src/lib/validators/auth.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/server/db/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import "server-only";
2-
31
import { env } from "@/env";
42
import { drizzle } from "drizzle-orm/postgres-js";
53
import postgres from "postgres";

src/server/db/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const users = pgTable(
1919
discordId: varchar("discord_id", { length: 255 }).unique(),
2020
email: varchar("email", { length: 255 }).unique().notNull(),
2121
emailVerified: boolean("email_verified").default(false).notNull(),
22-
hashedPassword: varchar("hashed_password", { length: 255 }),
22+
hashedPassword: varchar("hashed_password", { length: 63 }),
2323
avatar: varchar("avatar", { length: 255 }),
2424
stripeSubscriptionId: varchar("stripe_subscription_id", { length: 191 }),
2525
stripePriceId: varchar("stripe_price_id", { length: 191 }),

src/trpc/shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { type AppRouter } from "@/server/api/root";
66
export const transformer = superjson;
77

88
function getBaseUrl() {
9-
if (typeof window !== "undefined") return "";
9+
if (typeof window !== "undefined") return window.location.origin;
1010
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`;
1111
return `http://localhost:${process.env.PORT ?? 3000}`;
1212
}

0 commit comments

Comments
 (0)