diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..bd5535a --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +pnpm-lock.yaml diff --git a/src/common/auth.ts b/src/common/auth.ts index a11baed..909a368 100644 --- a/src/common/auth.ts +++ b/src/common/auth.ts @@ -5,10 +5,7 @@ import { psqlClient } from "./database"; import { ErrorCode, RESTError } from "./error"; import { Token, User } from "./types"; -export async function checkCredentials( - email: string, - password: string -): Promise { +export async function checkCredentials(email: string, password: string): Promise { const userQuery = await psqlClient.query("SELECT * FROM users WHERE email=$1", [email]); if (!userQuery.rowCount) throw new RESTError(ErrorCode.AuthError, "Invalid username or password"); diff --git a/src/common/error.ts b/src/common/error.ts index f3dbffe..a6a4381 100644 --- a/src/common/error.ts +++ b/src/common/error.ts @@ -17,7 +17,7 @@ export enum ErrorCode { */ export abstract class APIError extends Error { abstract location: "ws" | "rest"; - abstract extra: Record & { validation?: any; stack?: string; }; + abstract extra: Record & { validation?: any; stack?: string }; abstract statusCode: number; constructor( @@ -75,8 +75,8 @@ export class SocketError extends APIError { super(code, message); } - statusCode = 500 - message = "Internal Server Error" + statusCode = 500; + message = "Internal Server Error"; } /** diff --git a/src/common/moderate.ts b/src/common/moderate.ts index 518bc3f..d570d6a 100644 --- a/src/common/moderate.ts +++ b/src/common/moderate.ts @@ -104,5 +104,5 @@ export function moderateMessage(text: string) { } export function shouldModerate(text: string) { - return moderateMessage(text).newText !== text -} \ No newline at end of file + return moderateMessage(text).newText !== text; +} diff --git a/src/common/types.ts b/src/common/types.ts index 745124c..0b31114 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -16,4 +16,4 @@ export type Token = { }; export type Arguments = T extends (...args: infer U) => any ? U : never; -export type Argument = Arguments[Index]; \ No newline at end of file +export type Argument = Arguments[Index]; diff --git a/src/index.ts b/src/index.ts index 7297930..74543cd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,9 @@ -import 'dotenv/config.js'; +import "dotenv/config.js"; import fastify from "fastify"; import { bootstrap } from "fastify-decorators"; import { resolve } from "path"; -import { ERROR_HANDLER } from './common/error.js'; +import { ERROR_HANDLER } from "./common/error.js"; export const server = fastify({ logger: { @@ -25,7 +25,7 @@ server.register(bootstrap, { prefix: "/api" }); -server.setErrorHandler(ERROR_HANDLER) +server.setErrorHandler(ERROR_HANDLER); server.listen({ port: parseInt(process.env.PORT), host: process.env.HOST }, (err, address) => { if (err) { diff --git a/src/rest/auth.ts b/src/rest/auth.ts index d2d8e5b..23fc267 100644 --- a/src/rest/auth.ts +++ b/src/rest/auth.ts @@ -43,10 +43,9 @@ export default class AuthController { const body = req.body as LoginBody; const auth = await checkCredentials(body.email, body.password); - return { token: await generateToken(auth, true) }; + return { token: await generateToken(auth, true) }; } - @POST({ url: "/signup", options: { @@ -67,7 +66,7 @@ export default class AuthController { async signupHandler(req, res) { const body = req.body as SignupBody; if (!(await validateCaptcha(body.turnstileKey))) - throw new RESTError(ErrorCode.ValidationError, "Invalid captcha"); + throw new RESTError(ErrorCode.ValidationError, "Invalid captcha"); // Check for existing info if ( @@ -79,7 +78,7 @@ export default class AuthController { throw new RESTError(ErrorCode.ConflictError, "Username or email already exists"); // Moderate username - if (shouldModerate(body.username)) + if (shouldModerate(body.username)) throw new RESTError(ErrorCode.ValidationError, "Username contains restricted words"); // Hash password @@ -129,18 +128,14 @@ export default class AuthController { const token = (req.query as any).token; // Check if token is valid - const query = await psqlClient.query( - "SELECT id FROM email_verifications WHERE token=$1", - [token] - ); - if (query.rows.length === 0) - throw new RESTError(ErrorCode.NotFoundError, "Invalid token"); + const query = await psqlClient.query("SELECT id FROM email_verifications WHERE token=$1", [ + token + ]); + if (query.rows.length === 0) throw new RESTError(ErrorCode.NotFoundError, "Invalid token"); // Delete token await psqlClient.query("DELETE FROM email_verifications WHERE token=$1", [token]); - await psqlClient.query("UPDATE users SET activated=true WHERE id=$1", [ - query.rows[0].id - ]); + await psqlClient.query("UPDATE users SET activated=true WHERE id=$1", [query.rows[0].id]); return res.redirect(`https://${process.env.CLIENT_HOSTNAME}/login?confirmed=true`); } -} \ No newline at end of file +}