sdy

make utils.js

1 +import jwt from "jsonwebtoken";
2 +import { PrismaClient } from "@prisma/client";
3 +
4 +export const APP_SECRET = "a"; // TODO : value update to object
5 +
6 +export const prisma = new PrismaClient();
7 +
8 +export const getUserId = (context) => {
9 + const Authorization = context.request.get("Authorization");
10 + if (Authorization) {
11 + const token = Authorization.replace("Bearer ", "");
12 + const { userId } = jwt.verify(token, APP_SECRET);
13 + return userId;
14 + }
15 + throw new Error("There is no vaild user");
16 +};