Skip to content

Commit 76d35b8

Browse files
committed
changes for localhost mysql and verification email
1 parent c0a7b2c commit 76d35b8

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

database.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
2-
"defaultEnv": {"ENV": "NODE_ENV"},
2+
"defaultEnv": {
3+
"ENV": "NODE_ENV"
4+
},
35
"development": {
46
"driver": "mysql",
5-
"host": "mysql",
7+
"host": "localhost",
68
"port": "3306",
79
"user": "newuser",
810
"password": "password",

devenv.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"NODE_ENV": "development",
33
"PORT": 4000,
44
"MYSQL_USER": "newuser",
5-
"MYSQL_HOST": "mysql",
5+
"MYSQL_HOST": "localhost",
66
"MYSQL_PORT": "3306",
77
"MYSQL_PASSWORD": "password",
88
"MYSQL_DATABASE": "exp",

index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if (process.env.NODE_ENV == 'development') {
1+
if (process.env.NODE_ENV == 'development') {
22
require('env2')('./devenv.json');
33
}
44
else {
@@ -33,18 +33,19 @@ const requestlogging = {
3333

3434
const schemaWithMiddleware = applyMiddleware(schema, ...middlewares);
3535

36-
const context = ({ req }) => {
36+
const context = ({ req }) => {
3737
const token = req.headers.authorization;
38-
if (token) {
38+
if (token) {
3939
try {
40-
const { displayname, email, authoruid, languages, region } = jwt.verify(token, process.env.JWT_SECRET);
41-
return { displayname, email, authoruid, languages, region };
40+
const userAuthData = jwt.verify(token, process.env.JWT_SECRET);
41+
userAuthData.isAuthenticated = true;
42+
return userAuthData;
4243
} catch (e) {
43-
console.log('exception', e);
44-
throw Error('Some error happens.');
44+
console.log('exception', e.message);
45+
return { isAuthenticated: false };
4546
}
4647
}
47-
return {};
48+
return { isAuthenticated: false };
4849
}
4950

5051
const server = new ApolloServer({
@@ -106,6 +107,6 @@ app.listen(PORT, '0.0.0.0', err => {
106107
console.error(err);
107108
process.exit(0);
108109
}
109-
110+
110111
console.log(`Running server at http://localhost:${PORT} in ${NODE_ENV}`);
111112
});

src/mails/sendemail.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ import _ from 'lodash';
33
import path from 'path';
44
import SendMail from '../utils/sendemail';
55

6-
export default async ({ to, subject, templatepath, maildata }) => {
7-
const filepath = path.resolve(__dirname, templatepath);
6+
export default async ({ to, subject, templatepath, maildata }) => {
7+
if (process.env.NODE_ENV === 'development') {
8+
console.log(`Verification link=> ${maildata.url}`);
9+
return;
10+
}
811

9-
fs.readFile(filepath, { encoding: 'UTF-8' }, (err, templatedata) => {
12+
const filepath = path.resolve(__dirname, templatepath);
13+
fs.readFile(filepath, { encoding: 'UTF-8' }, (err, templatedata) => {
1014
if (!err) {
1115
const compiledTempate = _.template(templatedata);
1216
const html = compiledTempate(maildata);
13-
SendMail({to, subject, html});
17+
SendMail({ to, subject, html });
1418
}
15-
else {
19+
else {
1620
console.log(`[ERROR] reading templatepath ${templatepath} | Error: ${err}`);
1721
}
1822
})
19-
23+
2024
}

0 commit comments

Comments
 (0)