aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-10-02 19:56:02 +0200
committerMarvin Borner2020-10-02 19:56:02 +0200
commit762794cecdb0b12b58db0de16d31c8d7c216171c (patch)
tree4b442ae2e8ae9df80dac26cd31a574da4a5d896d
parent3ffa108bebadd448ba09a8931addba69fddfc72c (diff)
Switched to redis session store
-rw-r--r--app.js13
-rw-r--r--package.json4
-rw-r--r--tables.sql2
3 files changed, 16 insertions, 3 deletions
diff --git a/app.js b/app.js
index d318df7..adda55c 100644
--- a/app.js
+++ b/app.js
@@ -9,7 +9,18 @@ const quotes = require("./quotes");
const app = express();
// TODO: Use secure: true in production
-app.use(session({ secret: "keyboard cat", resave: false, saveUninitialized: true, cookie: { secure: false } }));
+const redis = require("redis");
+const RedisStore = require("connect-redis")(session);
+const redisClient = redis.createClient();
+app.use(
+ session({
+ store: new RedisStore({ client: redisClient }),
+ secret: "keyboard cat",
+ resave: false,
+ saveUninitialized: true,
+ cookie: { secure: false },
+ })
+);
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
diff --git a/package.json b/package.json
index a9691f4..6c65977 100644
--- a/package.json
+++ b/package.json
@@ -7,11 +7,13 @@
"license": "MIT",
"dependencies": {
"bcrypt": "^5.0.0",
+ "connect-redis": "^5.0.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-rate-limit": "^5.1.3",
"express-session": "^1.17.1",
"mariadb": "^2.4.2",
- "nanoid": "^3.1.12"
+ "nanoid": "^3.1.12",
+ "redis": "^3.0.2"
}
}
diff --git a/tables.sql b/tables.sql
index 8948860..516db23 100644
--- a/tables.sql
+++ b/tables.sql
@@ -26,7 +26,7 @@ CREATE TABLE IF NOT EXISTS class(
CREATE TABLE IF NOT EXISTS users(
id INTEGER PRIMARY KEY AUTO_INCREMENT,
- username VARCHAR(255) NOT NULL,
+ username VARCHAR(255) NOT NULL UNIQUE,
name VARCHAR(255) NOT NULL,
middlename VARCHAR(255) DEFAULT NULL,
surname VARCHAR(255) NOT NULL,