utils.js 494 Bytes
import jwt from "jsonwebtoken";
import { PrismaClient } from "@prisma/client";

export const APP_SECRET = "a"; // TODO : value update to object

export const prisma = new PrismaClient();

export const getUserId = (context) => {
  const Authorization = context.request.get("Authorization");
  if (Authorization) {
    const token = Authorization.replace("Bearer ", "");
    const { userId } = jwt.verify(token, APP_SECRET);
    return userId;
  }
  throw new Error("There is no vaild user");
};