feat: implement user session management with Redis and add game token verification
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { initTRPC } from '@trpc/server';
|
||||
import { initTRPC, TRPCError } from '@trpc/server';
|
||||
|
||||
import type { GameApiContext } from './context.js';
|
||||
|
||||
@@ -6,3 +6,17 @@ const t = initTRPC.context<GameApiContext>().create();
|
||||
|
||||
export const router = t.router;
|
||||
export const procedure = t.procedure;
|
||||
export const authedProcedure = t.procedure.use(({ ctx, next }) => {
|
||||
if (!ctx.auth) {
|
||||
throw new TRPCError({
|
||||
code: 'UNAUTHORIZED',
|
||||
message: 'Unauthorized',
|
||||
});
|
||||
}
|
||||
return next({
|
||||
ctx: {
|
||||
...ctx,
|
||||
auth: ctx.auth,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user