summaryrefslogtreecommitdiffstats
path: root/backend/src/index.js
diff options
context:
space:
mode:
authorWes Bos <wesbos@gmail.com>2018-05-15 22:15:36 -0400
committerWes Bos <wesbos@gmail.com>2018-05-15 22:15:36 -0400
commit3f9b14e3c1d7f47d9b3e48b94b3b5bf2c722205e (patch)
tree63373ce8c75e51305b7899af6c53903ef6c4f179 /backend/src/index.js
parentae1a94b08f5aba0c16c6536e388b4dd4a53120fd (diff)
migrate to cookies for jwt
Diffstat (limited to 'backend/src/index.js')
-rw-r--r--backend/src/index.js23
1 files changed, 17 insertions, 6 deletions
diff --git a/backend/src/index.js b/backend/src/index.js
index 04d13cc..6978225 100644
--- a/backend/src/index.js
+++ b/backend/src/index.js
@@ -3,14 +3,16 @@ require('dotenv').config({ path: 'variables.env' });
/* eslint-enable */
const jwt = require('jsonwebtoken');
const createServer = require('./createServer');
+const cookieParser = require('cookie-parser');
const server = createServer();
+server.express.use(cookieParser());
+
// 1. Check JWT
server.express.use((req, res, next) => {
- const Authorization = req.get('Authorization');
- if (Authorization) {
- const token = Authorization.replace('Bearer ', '');
+ const { token } = req.cookies;
+ if (token) {
const { userId } = jwt.verify(token, process.env.APP_SECRET);
req.userId = userId;
}
@@ -30,6 +32,15 @@ server.express.use(async (req, res, next) => {
next();
});
-server.start({ port: 4444 }, deets => {
- console.log(`Server is running on http://localhost:${deets.port}`);
-});
+server.start(
+ {
+ cors: {
+ credentials: true,
+ origin: process.env.FRONTEND_URL,
+ },
+ port: 4444,
+ },
+ deets => {
+ console.log(`Server is running on http://localhost:${deets.port}`);
+ }
+);