diff --git a/server/routes/api/auth.test.ts b/server/routes/api/auth/auth.test.ts similarity index 100% rename from server/routes/api/auth.test.ts rename to server/routes/api/auth/auth.test.ts diff --git a/server/routes/api/auth.ts b/server/routes/api/auth/auth.ts similarity index 85% rename from server/routes/api/auth.ts rename to server/routes/api/auth/auth.ts index add39dabe..6cdd62428 100644 --- a/server/routes/api/auth.ts +++ b/server/routes/api/auth/auth.ts @@ -17,10 +17,11 @@ import { import ValidateSSOAccessTask from "@server/queues/tasks/ValidateSSOAccessTask"; import { APIContext } from "@server/types"; import { getSessionsInCookie } from "@server/utils/authentication"; +import * as T from "./schema"; const router = new Router(); -router.post("auth.config", async (ctx: APIContext) => { +router.post("auth.config", async (ctx: APIContext) => { // If self hosted AND there is only one team then that team becomes the // brand for the knowledge base and it's guest signin option is used for the // root login page. @@ -108,7 +109,7 @@ router.post("auth.config", async (ctx: APIContext) => { }; }); -router.post("auth.info", auth(), async (ctx: APIContext) => { +router.post("auth.info", auth(), async (ctx: APIContext) => { const { user } = ctx.state.auth; const sessions = getSessionsInCookie(ctx); const signedInTeamIds = Object.keys(sessions); @@ -145,30 +146,35 @@ router.post("auth.info", auth(), async (ctx: APIContext) => { }; }); -router.post("auth.delete", auth(), transaction(), async (ctx: APIContext) => { - const { auth, transaction } = ctx.state; - const { user } = auth; +router.post( + "auth.delete", + auth(), + transaction(), + async (ctx: APIContext) => { + const { auth, transaction } = ctx.state; + const { user } = auth; - await user.rotateJwtSecret({ transaction }); - await Event.create( - { - name: "users.signout", - actorId: user.id, - userId: user.id, - teamId: user.teamId, - data: { - name: user.name, + await user.rotateJwtSecret({ transaction }); + await Event.create( + { + name: "users.signout", + actorId: user.id, + userId: user.id, + teamId: user.teamId, + data: { + name: user.name, + }, + ip: ctx.request.ip, }, - ip: ctx.request.ip, - }, - { - transaction, - } - ); + { + transaction, + } + ); - ctx.body = { - success: true, - }; -}); + ctx.body = { + success: true, + }; + } +); export default router; diff --git a/server/routes/api/auth/index.ts b/server/routes/api/auth/index.ts new file mode 100644 index 000000000..84e73ba83 --- /dev/null +++ b/server/routes/api/auth/index.ts @@ -0,0 +1 @@ +export { default } from "./auth"; diff --git a/server/routes/api/auth/schema.ts b/server/routes/api/auth/schema.ts new file mode 100644 index 000000000..f721f447d --- /dev/null +++ b/server/routes/api/auth/schema.ts @@ -0,0 +1,14 @@ +import { z } from "zod"; +import BaseSchema from "../BaseSchema"; + +export const AuthConfigSchema = BaseSchema; + +export type AuthConfigReq = z.infer; + +export const AuthInfoSchema = BaseSchema; + +export type AuthInfoReq = z.infer; + +export const AuthDeleteSchema = BaseSchema; + +export type AuthDeleteReq = z.infer;