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

@@ -12,19 +12,19 @@ import { encodeToken } from "../../lib/JsonWebToken";
export const post: APIRoute = async ({ request }) => {
const body = await request.json();
if (!body.hasOwnProperty("username") || !body.hasOwnProperty("password")) {
return MissingPropertyError(["username", "password"]);
if (!body.hasOwnProperty("email") || !body.hasOwnProperty("password")) {
return MissingPropertyError(["email", "password"]);
}
const user = await User.fromUsername(body.username);
const user = await User.fromEmail(body.email);
if (!user) {
return error(["Invalid username or password."]);
return error(["Invalid email or password."]);
}
// Validate Password
if (!validatePassword(user.password, body.password)) {
return error(["Invalid username or password."]);
return error(["Invalid email or password."]);
}
const expiry = moment().add(2, "days").unix();