Registrierung und Login gefixt
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user