chore: schema for api/auth (#5481)
This commit is contained in:
@@ -17,10 +17,11 @@ import {
|
|||||||
import ValidateSSOAccessTask from "@server/queues/tasks/ValidateSSOAccessTask";
|
import ValidateSSOAccessTask from "@server/queues/tasks/ValidateSSOAccessTask";
|
||||||
import { APIContext } from "@server/types";
|
import { APIContext } from "@server/types";
|
||||||
import { getSessionsInCookie } from "@server/utils/authentication";
|
import { getSessionsInCookie } from "@server/utils/authentication";
|
||||||
|
import * as T from "./schema";
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
router.post("auth.config", async (ctx: APIContext) => {
|
router.post("auth.config", async (ctx: APIContext<T.AuthConfigReq>) => {
|
||||||
// If self hosted AND there is only one team then that team becomes the
|
// 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
|
// brand for the knowledge base and it's guest signin option is used for the
|
||||||
// root login page.
|
// 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<T.AuthInfoReq>) => {
|
||||||
const { user } = ctx.state.auth;
|
const { user } = ctx.state.auth;
|
||||||
const sessions = getSessionsInCookie(ctx);
|
const sessions = getSessionsInCookie(ctx);
|
||||||
const signedInTeamIds = Object.keys(sessions);
|
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) => {
|
router.post(
|
||||||
const { auth, transaction } = ctx.state;
|
"auth.delete",
|
||||||
const { user } = auth;
|
auth(),
|
||||||
|
transaction(),
|
||||||
|
async (ctx: APIContext<T.AuthDeleteReq>) => {
|
||||||
|
const { auth, transaction } = ctx.state;
|
||||||
|
const { user } = auth;
|
||||||
|
|
||||||
await user.rotateJwtSecret({ transaction });
|
await user.rotateJwtSecret({ transaction });
|
||||||
await Event.create(
|
await Event.create(
|
||||||
{
|
{
|
||||||
name: "users.signout",
|
name: "users.signout",
|
||||||
actorId: user.id,
|
actorId: user.id,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
data: {
|
data: {
|
||||||
name: user.name,
|
name: user.name,
|
||||||
|
},
|
||||||
|
ip: ctx.request.ip,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
{
|
||||||
},
|
transaction,
|
||||||
{
|
}
|
||||||
transaction,
|
);
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
success: true,
|
success: true,
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
1
server/routes/api/auth/index.ts
Normal file
1
server/routes/api/auth/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { default } from "./auth";
|
||||||
14
server/routes/api/auth/schema.ts
Normal file
14
server/routes/api/auth/schema.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
import BaseSchema from "../BaseSchema";
|
||||||
|
|
||||||
|
export const AuthConfigSchema = BaseSchema;
|
||||||
|
|
||||||
|
export type AuthConfigReq = z.infer<typeof AuthConfigSchema>;
|
||||||
|
|
||||||
|
export const AuthInfoSchema = BaseSchema;
|
||||||
|
|
||||||
|
export type AuthInfoReq = z.infer<typeof AuthInfoSchema>;
|
||||||
|
|
||||||
|
export const AuthDeleteSchema = BaseSchema;
|
||||||
|
|
||||||
|
export type AuthDeleteReq = z.infer<typeof AuthDeleteSchema>;
|
||||||
Reference in New Issue
Block a user