aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/routers/users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/trpc/routers/users.ts')
-rw-r--r--packages/trpc/routers/users.ts46
1 files changed, 43 insertions, 3 deletions
diff --git a/packages/trpc/routers/users.ts b/packages/trpc/routers/users.ts
index d3bc06d9..c11a0ffd 100644
--- a/packages/trpc/routers/users.ts
+++ b/packages/trpc/routers/users.ts
@@ -9,7 +9,9 @@ import {
zUserSettingsSchema,
zUserStatsResponseSchema,
zWhoAmIResponseSchema,
+ zWrappedStatsResponseSchema,
} from "@karakeep/shared/types/users";
+import { validateRedirectUrl } from "@karakeep/shared/utils/redirectUrl";
import {
adminProcedure,
@@ -30,7 +32,7 @@ export const usersAppRouter = router({
maxRequests: 3,
}),
)
- .input(zSignUpSchema)
+ .input(zSignUpSchema.and(z.object({ redirectUrl: z.string().optional() })))
.output(
z.object({
id: z.string(),
@@ -64,7 +66,11 @@ export const usersAppRouter = router({
});
}
}
- const user = await User.create(ctx, input);
+ const validatedRedirectUrl = validateRedirectUrl(input.redirectUrl);
+ const user = await User.create(ctx, {
+ ...input,
+ redirectUrl: validatedRedirectUrl,
+ });
return {
id: user.id,
name: user.name,
@@ -136,6 +142,24 @@ export const usersAppRouter = router({
const user = await User.fromCtx(ctx);
return await user.getStats();
}),
+ wrapped: authedProcedure
+ .output(zWrappedStatsResponseSchema)
+ .query(async ({ ctx }) => {
+ throw new TRPCError({
+ code: "BAD_REQUEST",
+ message: "This endpoint is currently disabled",
+ });
+ const user = await User.fromCtx(ctx);
+ return await user.getWrappedStats(2025);
+ }),
+ hasWrapped: authedProcedure.output(z.boolean()).query(async ({ ctx }) => {
+ throw new TRPCError({
+ code: "BAD_REQUEST",
+ message: "This endpoint is currently disabled",
+ });
+ const user = await User.fromCtx(ctx);
+ return await user.hasWrapped();
+ }),
settings: authedProcedure
.output(zUserSettingsSchema)
.query(async ({ ctx }) => {
@@ -148,6 +172,16 @@ export const usersAppRouter = router({
const user = await User.fromCtx(ctx);
await user.updateSettings(input);
}),
+ updateAvatar: authedProcedure
+ .input(
+ z.object({
+ assetId: z.string().nullable(),
+ }),
+ )
+ .mutation(async ({ input, ctx }) => {
+ const user = await User.fromCtx(ctx);
+ await user.updateAvatar(input.assetId);
+ }),
verifyEmail: publicProcedure
.use(
createRateLimitMiddleware({
@@ -177,10 +211,16 @@ export const usersAppRouter = router({
.input(
z.object({
email: z.string().email(),
+ redirectUrl: z.string().optional(),
}),
)
.mutation(async ({ input, ctx }) => {
- await User.resendVerificationEmail(ctx, input.email);
+ const validatedRedirectUrl = validateRedirectUrl(input.redirectUrl);
+ await User.resendVerificationEmail(
+ ctx,
+ input.email,
+ validatedRedirectUrl,
+ );
return { success: true };
}),
forgotPassword: publicProcedure