fix rate limit async issue, kill old code

This commit is contained in:
Michael Freno
2026-01-06 23:52:51 -05:00
parent 445ab6d7de
commit 5e247e54cb
12 changed files with 201 additions and 139 deletions

View File

@@ -1206,7 +1206,7 @@ export const authRouter = createTRPCRouter({
// Apply rate limiting
const clientIP = getClientIP(getH3Event(ctx));
rateLimitRegistration(clientIP, getH3Event(ctx));
await rateLimitRegistration(clientIP, getH3Event(ctx));
// Schema already validates password match, but double check
if (password !== passwordConfirmation) {
@@ -1297,7 +1297,7 @@ export const authRouter = createTRPCRouter({
// Apply rate limiting
const clientIP = getClientIP(getH3Event(ctx));
rateLimitLogin(email, clientIP, getH3Event(ctx));
await rateLimitLogin(email, clientIP, getH3Event(ctx));
const conn = ConnectionFactory();
const res = await conn.execute({
@@ -1602,7 +1602,7 @@ export const authRouter = createTRPCRouter({
// Apply rate limiting
const clientIP = getClientIP(getH3Event(ctx));
rateLimitPasswordReset(clientIP, getH3Event(ctx));
await rateLimitPasswordReset(clientIP, getH3Event(ctx));
try {
const requested = getCookie(getH3Event(ctx), "passwordResetRequested");
@@ -1857,7 +1857,7 @@ export const authRouter = createTRPCRouter({
// Apply rate limiting
const clientIP = getClientIP(getH3Event(ctx));
rateLimitEmailVerification(clientIP, getH3Event(ctx));
await rateLimitEmailVerification(clientIP, getH3Event(ctx));
try {
const requested = getCookie(
@@ -2269,7 +2269,7 @@ export const authRouter = createTRPCRouter({
// Admin endpoints for session management
cleanupSessions: publicProcedure.mutation(async ({ ctx }) => {
// Get user ID to check admin status
const userId = await getUserID(getH3Event(ctx));
const userId = ctx.userId;
if (!userId) {
throw new TRPCError({
code: "UNAUTHORIZED",
@@ -2318,7 +2318,7 @@ export const authRouter = createTRPCRouter({
getSessionStats: publicProcedure.query(async ({ ctx }) => {
// Get user ID to check admin status
const userId = await getUserID(getH3Event(ctx));
const userId = ctx.userId;
if (!userId) {
throw new TRPCError({
code: "UNAUTHORIZED",

View File

@@ -1,7 +1,6 @@
import { createTRPCRouter, publicProcedure } from "../utils";
import { ConnectionFactory } from "~/server/utils";
import { z } from "zod";
import { getUserID } from "~/server/auth";
import { TRPCError } from "@trpc/server";
import diff from "fast-diff";
@@ -86,7 +85,7 @@ export const postHistoryRouter = createTRPCRouter({
})
)
.mutation(async ({ input, ctx }) => {
const userId = await getUserID(ctx.event.nativeEvent);
const userId = ctx.userId;
if (!userId) {
throw new TRPCError({
@@ -168,7 +167,7 @@ export const postHistoryRouter = createTRPCRouter({
getHistory: publicProcedure
.input(z.object({ postId: z.number() }))
.query(async ({ input, ctx }) => {
const userId = await getUserID(ctx.event.nativeEvent);
const userId = ctx.userId;
if (!userId) {
throw new TRPCError({
@@ -243,7 +242,7 @@ export const postHistoryRouter = createTRPCRouter({
restore: publicProcedure
.input(z.object({ historyId: z.number() }))
.query(async ({ input, ctx }) => {
const userId = await getUserID(ctx.event.nativeEvent);
const userId = ctx.userId;
if (!userId) {
throw new TRPCError({

View File

@@ -1,11 +1,6 @@
import { createTRPCRouter, publicProcedure } from "../utils";
import { TRPCError } from "@trpc/server";
import {
ConnectionFactory,
getUserID,
hashPassword,
checkPassword
} from "~/server/utils";
import { ConnectionFactory, hashPassword, checkPassword } from "~/server/utils";
import { setCookie } from "vinxi/http";
import type { User } from "~/db/types";
import { toUserProfile } from "~/types/user";
@@ -20,7 +15,7 @@ import {
export const userRouter = createTRPCRouter({
getProfile: publicProcedure.query(async ({ ctx }) => {
const userId = await getUserID(ctx.event.nativeEvent);
const userId = ctx.userId;
if (!userId) {
throw new TRPCError({
@@ -49,7 +44,7 @@ export const userRouter = createTRPCRouter({
updateEmail: publicProcedure
.input(updateEmailSchema)
.mutation(async ({ input, ctx }) => {
const userId = await getUserID(ctx.event.nativeEvent);
const userId = ctx.userId;
if (!userId) {
throw new TRPCError({
@@ -83,7 +78,7 @@ export const userRouter = createTRPCRouter({
updateDisplayName: publicProcedure
.input(updateDisplayNameSchema)
.mutation(async ({ input, ctx }) => {
const userId = await getUserID(ctx.event.nativeEvent);
const userId = ctx.userId;
if (!userId) {
throw new TRPCError({
@@ -112,7 +107,7 @@ export const userRouter = createTRPCRouter({
updateProfileImage: publicProcedure
.input(updateProfileImageSchema)
.mutation(async ({ input, ctx }) => {
const userId = await getUserID(ctx.event.nativeEvent);
const userId = ctx.userId;
if (!userId) {
throw new TRPCError({
@@ -141,7 +136,7 @@ export const userRouter = createTRPCRouter({
changePassword: publicProcedure
.input(changePasswordSchema)
.mutation(async ({ input, ctx }) => {
const userId = await getUserID(ctx.event.nativeEvent);
const userId = ctx.userId;
if (!userId) {
throw new TRPCError({
@@ -214,7 +209,7 @@ export const userRouter = createTRPCRouter({
setPassword: publicProcedure
.input(setPasswordSchema)
.mutation(async ({ input, ctx }) => {
const userId = await getUserID(ctx.event.nativeEvent);
const userId = ctx.userId;
if (!userId) {
throw new TRPCError({
@@ -275,7 +270,7 @@ export const userRouter = createTRPCRouter({
deleteAccount: publicProcedure
.input(deleteAccountSchema)
.mutation(async ({ input, ctx }) => {
const userId = await getUserID(ctx.event.nativeEvent);
const userId = ctx.userId;
if (!userId) {
throw new TRPCError({