diff --git a/database.json b/database.json index a338538..b522d78 100644 --- a/database.json +++ b/database.json @@ -1,8 +1,10 @@ { - "defaultEnv": {"ENV": "NODE_ENV"}, + "defaultEnv": { + "ENV": "NODE_ENV" + }, "development": { "driver": "mysql", - "host": "mysql", + "host": "localhost", "port": "3306", "user": "newuser", "password": "password", diff --git a/devenv.json b/devenv.json index 8b1b6ac..e65108a 100644 --- a/devenv.json +++ b/devenv.json @@ -2,7 +2,7 @@ "NODE_ENV": "development", "PORT": 4000, "MYSQL_USER": "newuser", - "MYSQL_HOST": "mysql", + "MYSQL_HOST": "localhost", "MYSQL_PORT": "3306", "MYSQL_PASSWORD": "password", "MYSQL_DATABASE": "exp", diff --git a/index.js b/index.js index 653f74f..e9b8d90 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -if (process.env.NODE_ENV == 'development') { +if (process.env.NODE_ENV == 'development') { require('env2')('./devenv.json'); } else { @@ -33,18 +33,19 @@ const requestlogging = { const schemaWithMiddleware = applyMiddleware(schema, ...middlewares); -const context = ({ req }) => { +const context = ({ req }) => { const token = req.headers.authorization; - if (token) { + if (token) { try { - const { displayname, email, authoruid, languages, region } = jwt.verify(token, process.env.JWT_SECRET); - return { displayname, email, authoruid, languages, region }; + const userAuthData = jwt.verify(token, process.env.JWT_SECRET); + userAuthData.isAuthenticated = true; + return userAuthData; } catch (e) { - console.log('exception', e); - throw Error('Some error happens.'); + console.log('exception', e.message); + return { isAuthenticated: false }; } } - return {}; + return { isAuthenticated: false }; } const server = new ApolloServer({ @@ -106,6 +107,6 @@ app.listen(PORT, '0.0.0.0', err => { console.error(err); process.exit(0); } - + console.log(`Running server at http://localhost:${PORT} in ${NODE_ENV}`); }); diff --git a/src/mails/sendemail.js b/src/mails/sendemail.js index b907db5..02084d6 100644 --- a/src/mails/sendemail.js +++ b/src/mails/sendemail.js @@ -3,18 +3,22 @@ import _ from 'lodash'; import path from 'path'; import SendMail from '../utils/sendemail'; -export default async ({ to, subject, templatepath, maildata }) => { - const filepath = path.resolve(__dirname, templatepath); +export default async ({ to, subject, templatepath, maildata }) => { + if (process.env.NODE_ENV === 'development') { + console.log(`Verification link=> ${maildata.url}`); + return; + } - fs.readFile(filepath, { encoding: 'UTF-8' }, (err, templatedata) => { + const filepath = path.resolve(__dirname, templatepath); + fs.readFile(filepath, { encoding: 'UTF-8' }, (err, templatedata) => { if (!err) { const compiledTempate = _.template(templatedata); const html = compiledTempate(maildata); - SendMail({to, subject, html}); + SendMail({ to, subject, html }); } - else { + else { console.log(`[ERROR] reading templatepath ${templatepath} | Error: ${err}`); } }) - + } \ No newline at end of file