coolify/apps/server/src/router/context.ts

20 lines
550 B
TypeScript
Raw Normal View History

2022-12-12 07:44:23 +00:00
import { inferAsyncReturnType } from '@trpc/server';
import { CreateFastifyContextOptions } from '@trpc/server/adapters/fastify';
import jwt from 'jsonwebtoken';
import { env } from '../env';
export interface User {
name: string | string[];
}
export function createContext({ req, res }: CreateFastifyContextOptions) {
const token = req.headers.authorization;
if (token) {
const user = jwt.verify(token, env.COOLIFY_SECRET_KEY);
console.log(user);
}
return { req, res };
}
export type Context = inferAsyncReturnType<typeof createContext>;