ahebwa49
02/20/2019, 4:58 PMimport jwt from "jsonwebtoken";
import { Context } from ".";
export const APP_SECRET = "GraphQL-is-awesome";
export function getUserId(context: Context): string {
const bearerToken = context.request.get("Authorization");
if (!bearerToken) {
throw new Error("Not Authenticated");
}
const token: string = bearerToken.replace("Bearer", "");
const userId: string = jwt.verify(token, APP_SECRET) as string;
return userId;
}
Ishaan
02/21/2019, 10:44 AM