This commit is contained in:
Andras Bacsai
2022-12-12 14:48:56 +01:00
parent 62f2196a0c
commit 2009dc11db
207 changed files with 9062 additions and 160 deletions

View 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>;