Continue merge user

This commit is contained in:
Tuan Dang
2024-04-25 17:02:55 -07:00
parent d9005e8665
commit 8ff407927c
16 changed files with 337 additions and 26 deletions
@@ -2,6 +2,7 @@ import { z } from "zod";
import { AuthTokenSessionsSchema, OrganizationsSchema, UserEncryptionKeysSchema, UsersSchema } from "@app/db/schemas";
import { ApiKeysSchema } from "@app/db/schemas/api-keys";
import { getConfig } from "@app/lib/config/env";
import { authRateLimit, readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMethod, AuthMode } from "@app/services/auth/auth-type";
@@ -68,6 +69,38 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
}
});
server.route({
method: "POST",
url: "/me/users/merge-user",
config: {
rateLimit: writeLimit
},
schema: {
body: z.object({
username: z.string().trim()
}),
response: {
200: z.object({
user: UsersSchema
})
}
},
preHandler: verifyAuth([AuthMode.JWT]),
handler: async (req, res) => {
const appCfg = getConfig();
const user = await server.services.user.mergeUsers(req.permission.id, req.body.username);
void res.cookie("jid", "", {
httpOnly: true,
path: "/",
sameSite: "strict",
secure: appCfg.HTTPS_ENABLED
});
return {
user
};
}
});
server.route({
method: "PATCH",
url: "/me/mfa",