-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1999934
commit 365d68d
Showing
7 changed files
with
45 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,23 @@ | ||
import koa from 'koa'; | ||
import router from "./routes"; | ||
import router from './routes'; | ||
import bodyParser from 'koa-bodyparser'; | ||
import cors from "koa-cors" | ||
import jwtMiddleware from 'koa-jwt'; | ||
|
||
import cors from 'koa-cors'; | ||
|
||
const host = process.env.HOST ?? 'localhost'; | ||
const port = process.env.PORT ? Number(process.env.PORT) : 8080; | ||
const secretKey = 'your-secret-key'; | ||
|
||
const app = new koa(); | ||
app.use(cors({ | ||
origin: '*', | ||
credentials: true, | ||
headers: ['Content-Type', 'Authorization'], | ||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'] | ||
})); | ||
app.use(jwtMiddleware({ | ||
secret: secretKey, | ||
passthrough: true, | ||
})); | ||
app.use(bodyParser()) | ||
app.use( | ||
cors({ | ||
origin: '*', | ||
credentials: true, | ||
headers: ['Content-Type', 'Authorization'], | ||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], | ||
}) | ||
); | ||
app.use(bodyParser()); | ||
app.use(router.routes()).use(router.allowedMethods()); | ||
|
||
app.listen(port, host, () => { | ||
console.log(`[ ready ] http://${host}:${port}`); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './jwt'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import koaJwt from 'koa-jwt'; | ||
import { jwtSecret } from '../utils'; | ||
|
||
export const jwtVal = koaJwt({ | ||
secret: jwtSecret, // Should not be hardcoded | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const jwtSecret = 'n6dHKHspDp'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './config'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import { createTransport } from "nodemailer"; | ||
import { createTransport } from 'nodemailer'; | ||
|
||
export const sendOTPEmail = async (email, otp) => { | ||
const transporter = createTransport({ | ||
service: 'gmail', | ||
auth: { | ||
user: '[email protected]', | ||
pass: 'tlrq fspt ecvu rcmi', | ||
}, | ||
}); | ||
const mailOptions = { | ||
from: '[email protected]', | ||
to: email, | ||
subject: 'Your OTP Code', | ||
text: `Your OTP code is ${otp}`, | ||
}; | ||
await transporter.sendMail(mailOptions); | ||
}; | ||
const transporter = createTransport({ | ||
service: 'gmail', | ||
auth: { | ||
user: '[email protected]', | ||
pass: '', | ||
}, | ||
}); | ||
|
||
const mailOptions = { | ||
from: '[email protected]', | ||
to: email, | ||
subject: 'Your OTP Code', | ||
text: `Your OTP code is ${otp}`, | ||
}; | ||
|
||
await transporter.sendMail(mailOptions); | ||
}; |