diff --git a/src/routes/auth/logout.ts b/src/routes/auth/logout.ts new file mode 100644 index 0000000..e1453df --- /dev/null +++ b/src/routes/auth/logout.ts @@ -0,0 +1,77 @@ +import e from "@edgedb"; +import { DATABASE_DELETE_FAILED, UNAUTHORIZED } from "constants/responses"; +import { Elysia } from "elysia"; +import { HttpStatusCode } from "elysia-http-status-code"; +import { client } from "index"; +import { auth } from "plugins/auth"; +import { promiseResult } from "utils/errors"; +import { responseBuilder } from "utils/response"; + +export const logoutRouter = new Elysia() + .use(HttpStatusCode()) + .use(auth) + .delete("/all", async ({ auth, set, httpStatus }) => { + if (!auth.isAuthorized) { + set.status = httpStatus.HTTP_401_UNAUTHORIZED; + return UNAUTHORIZED; + } + if (auth.createdBy !== "login") { + set.status = httpStatus.HTTP_403_FORBIDDEN; + return responseBuilder("error", { + error: + "Access token must be generated using log in and not a refresh token", + }); + } + + const delQuery = e.count( + e.delete(e.RefreshToken, (t) => ({ + filter: e.op(t[" { + if (!auth.isAuthorized) { + set.status = httpStatus.HTTP_401_UNAUTHORIZED; + return UNAUTHORIZED; + } + + const delQuery = e.delete(e.RefreshToken, (t) => ({ + filter_single: e.op( + e.op(t[" { @@ -99,68 +97,3 @@ export const refreshTokenRouter = new Elysia({ prefix: "/refresh-token" }) detail: { tags: ["Auth"] }, }, ) - .delete("/all", async ({ auth, set, httpStatus }) => { - if (!auth.isAuthorized) { - set.status = httpStatus.HTTP_401_UNAUTHORIZED; - return UNAUTHORIZED; - } - if (auth.createdBy !== "login") { - set.status = httpStatus.HTTP_403_FORBIDDEN; - return responseBuilder("error", { - error: - "Access token must be generated using log in and not a refresh token", - }); - } - - const delQuery = e.count( - e.delete(e.RefreshToken, (t) => ({ - filter: e.op(t[" { - if (!auth.isAuthorized) { - set.status = httpStatus.HTTP_401_UNAUTHORIZED; - return UNAUTHORIZED; - } - - const delQuery = e.delete(e.RefreshToken, (t) => ({ - filter_single: e.op( - e.op(t["(callback: () => Promise) => { }) as const, ) .catch( - (e) => + (e: Error) => ({ status: "error", error: e,