Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { execute, subscribe } from 'graphql';
import { SubscriptionServer } from 'subscriptions-transport-ws';
import joinMonsterAdapt from 'join-monster-graphql-tools-adapter';
import typeDefs from './schema';
import resolvers from './resolvers';
import models from './models';
import { refreshTokens } from './auth';
import joinMonsterMetadata from './joinMonsterMetadata';
const schema = makeExecutableSchema({
typeDefs,
resolvers,
});
joinMonsterAdapt(schema, joinMonsterMetadata);
const SECRET = 'aslkdjlkaj10830912039jlkoaiuwerasdjflkasd';
const app = express();
const addUser = async (req, res, next) => {
const token = req.headers['x-token'];
console.log(token);
if (token) {
try {
const { user } = jwt.verify(token, SECRET);
req.user = user;
} catch (err) {
const refreshToken = req.headers['x-refresh-token'];
const newTokens = await refreshTokens(token, refreshToken, models, SECRET);
if (newTokens.token && newTokens.refreshToken) {