wip trpc
This commit is contained in:
22
apps/server/src/trpc/context.ts
Normal file
22
apps/server/src/trpc/context.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { inferAsyncReturnType } from '@trpc/server';
|
||||
import { CreateFastifyContextOptions } from '@trpc/server/adapters/fastify';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { env } from '../env';
|
||||
export interface User {
|
||||
userId: string;
|
||||
teamId: string;
|
||||
permission: string;
|
||||
isAdmin: boolean;
|
||||
iat: number;
|
||||
}
|
||||
|
||||
export function createContext({ req }: CreateFastifyContextOptions) {
|
||||
const token = req.headers.authorization;
|
||||
let user: User | null = null;
|
||||
if (token) {
|
||||
user = jwt.verify(token, env.COOLIFY_SECRET_KEY) as User;
|
||||
}
|
||||
return { user };
|
||||
}
|
||||
|
||||
export type Context = inferAsyncReturnType<typeof createContext>;
|
Reference in New Issue
Block a user