Add sqlite session management
This commit is contained in:
parent
dbf59e42a8
commit
07c2fc0fd1
12
package-lock.json
generated
12
package-lock.json
generated
@ -10,6 +10,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
"body-parser": "^1.20.2",
|
"body-parser": "^1.20.2",
|
||||||
|
"connect-sqlite3": "^0.9.16",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
@ -444,6 +445,17 @@
|
|||||||
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
|
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
|
||||||
"devOptional": true
|
"devOptional": true
|
||||||
},
|
},
|
||||||
|
"node_modules/connect-sqlite3": {
|
||||||
|
"version": "0.9.16",
|
||||||
|
"resolved": "https://registry.npmjs.org/connect-sqlite3/-/connect-sqlite3-0.9.16.tgz",
|
||||||
|
"integrity": "sha512-2gqo0QmcBBL8p8+eqpBETn7RgM/PaoKvpQGl8PfjEgwlr0VuMYNMxRJRrRCo3KR3fxMYeSsCw2tGNG0JKN9Nvg==",
|
||||||
|
"dependencies": {
|
||||||
|
"sqlite3": "^5.0.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.4.x"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/console-control-strings": {
|
"node_modules/console-control-strings": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
|
||||||
|
11
package.json
11
package.json
@ -8,17 +8,18 @@
|
|||||||
"dev": "nodemon server.js"
|
"dev": "nodemon server.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"bcryptjs": "^2.4.3",
|
||||||
|
"body-parser": "^1.20.2",
|
||||||
|
"connect-sqlite3": "^0.9.16",
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"dotenv": "^16.3.1",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"sqlite3": "^5.1.6",
|
|
||||||
"express-session": "^1.17.3",
|
"express-session": "^1.17.3",
|
||||||
"passport": "^0.6.0",
|
"passport": "^0.6.0",
|
||||||
"passport-google-oauth20": "^2.0.0",
|
"passport-google-oauth20": "^2.0.0",
|
||||||
"passport-instagram": "^1.0.0",
|
"passport-instagram": "^1.0.0",
|
||||||
"passport-local": "^1.0.0",
|
"passport-local": "^1.0.0",
|
||||||
"bcryptjs": "^2.4.3",
|
"sqlite3": "^5.1.6"
|
||||||
"body-parser": "^1.20.2",
|
|
||||||
"cors": "^2.8.5",
|
|
||||||
"dotenv": "^16.3.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"nodemon": "^3.0.1"
|
"nodemon": "^3.0.1"
|
||||||
|
10
server.js
10
server.js
@ -1,6 +1,7 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const sqlite3 = require('sqlite3').verbose();
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
const session = require('express-session');
|
const session = require('express-session');
|
||||||
|
const SQLiteStore = require('connect-sqlite3')(session);
|
||||||
const passport = require('passport');
|
const passport = require('passport');
|
||||||
const GoogleStrategy = require('passport-google-oauth20').Strategy;
|
const GoogleStrategy = require('passport-google-oauth20').Strategy;
|
||||||
const InstagramStrategy = require('passport-instagram').Strategy;
|
const InstagramStrategy = require('passport-instagram').Strategy;
|
||||||
@ -91,10 +92,17 @@ app.use(bodyParser.urlencoded({ extended: true }));
|
|||||||
app.use(express.static(path.join(__dirname, 'public')));
|
app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
|
||||||
app.use(session({
|
app.use(session({
|
||||||
|
store: new SQLiteStore({
|
||||||
|
db: 'water_stations.db',
|
||||||
|
table: 'sessions'
|
||||||
|
}),
|
||||||
secret: process.env.SESSION_SECRET || 'your-secret-key',
|
secret: process.env.SESSION_SECRET || 'your-secret-key',
|
||||||
resave: false,
|
resave: false,
|
||||||
saveUninitialized: false,
|
saveUninitialized: false,
|
||||||
cookie: { secure: false } // Set to true in production with HTTPS
|
cookie: {
|
||||||
|
secure: false, // Set to true in production with HTTPS
|
||||||
|
maxAge: 7 * 24 * 60 * 60 * 1000 // 7 days
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
app.use(passport.initialize());
|
app.use(passport.initialize());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user