Registrierung und Login gefixt

This commit is contained in:
Moritz Utcke
2023-04-14 15:30:52 +04:00
parent 24c29214be
commit 452e6aaa28
5 changed files with 16 additions and 30 deletions

View File

@@ -24,12 +24,12 @@ export class User {
return user;
}
public static async fromUsername(username: string): Promise<UserType | null> {
if (!username || typeof username !== "string") {
public static async fromEmail(email: string): Promise<UserType | null> {
if (!email || typeof email !== "string") {
return null;
}
const user = await db<UserType>("users").select("*").where("username", username).first();
const user = await db<UserType>("users").select("*").where("email", email).first();
if (!user) {
return null;
@@ -66,7 +66,6 @@ export class User {
const hashedPassword = hashPassword(user.password);
const result = await db<UserType>("users").insert({
username: user.username,
email: user.email,
password: hashedPassword,
uid: uid

View File

@@ -1,7 +1,6 @@
import { z } from "zod"
export const UserTypeValidator = z.object({
username: z.string().min(4).max(64),
id: z.number(),
uid: z.string().length(36),
email: z.string().max(255),
@@ -9,7 +8,6 @@ export const UserTypeValidator = z.object({
})
export const UserRegisterValidator = z.object({
username: z.string().min(4).max(64),
email: z.string().max(255),
password: z.string().min(6),
})