Redesign WatchLink application UI
All checks were successful
Template Compliance / compliance (push) Successful in 5s
Build / build (push) Successful in 12m36s
Release Dry Run / release-dry-run (push) Successful in 1m33s

This commit is contained in:
MrSphay
2026-05-15 20:13:29 +02:00
parent cea591b587
commit 9fbd79c7ef
22 changed files with 2370 additions and 533 deletions

View File

@@ -2,8 +2,9 @@
import { compare, hash } from "bcryptjs";
import { redirect } from "next/navigation";
import { Prisma, type User } from "@prisma/client";
import { prisma } from "./prisma";
import { setSession } from "./session";
import { clearSession, setSession } from "./session";
function normalizeUsername(value: FormDataEntryValue | null) {
return String(value || "")
@@ -17,24 +18,33 @@ export async function registerUser(formData: FormData) {
const password = String(formData.get("password") || "");
if (!username || password.length < 10) {
throw new Error("Username is required and password must be at least 10 characters.");
redirect("/register?error=invalid");
}
const passwordHash = await hash(password, 12);
const user = await prisma.user.create({
data: {
username,
displayName: username,
passwordHash,
ownedRooms: {
create: {
slug: `@${username}`,
name: `${username}'s room`,
visibility: "FRIENDS"
let user: User;
try {
user = await prisma.user.create({
data: {
username,
displayName: username,
passwordHash,
ownedRooms: {
create: {
slug: `@${username}`,
name: `${username}'s room`,
visibility: "FRIENDS"
}
}
}
});
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002") {
redirect("/register?error=username");
}
});
throw error;
}
await setSession(user.id);
redirect("/dashboard");
@@ -46,14 +56,19 @@ export async function loginUser(formData: FormData) {
const user = await prisma.user.findUnique({ where: { username } });
if (!user) {
throw new Error("Invalid username or password.");
redirect("/login?error=credentials");
}
const ok = await compare(password, user.passwordHash);
if (!ok) {
throw new Error("Invalid username or password.");
redirect("/login?error=credentials");
}
await setSession(user.id);
redirect("/dashboard");
}
export async function logoutUser() {
await clearSession();
redirect("/login");
}