35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
const SessionStore = require('better-sqlite3-session-store')(require('express-session'));
|
|
const { getDb } = require('./src/db');
|
|
|
|
try {
|
|
const db = getDb();
|
|
// Check if sessions table exists
|
|
const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table'").all();
|
|
console.log('Tables:', tables.map(t => t.name));
|
|
|
|
// Try creating a session
|
|
const store = new SessionStore({
|
|
client: db,
|
|
table: 'sessions',
|
|
expired: { clear: false },
|
|
});
|
|
|
|
// Try creating a session
|
|
const session = { userId: 1, username: 'test' };
|
|
store.set('test-session-id', session, (err) => {
|
|
if (err) {
|
|
console.log('SET ERROR:', err.message);
|
|
console.log('ERROR STACK:', err.stack);
|
|
} else {
|
|
console.log('SET OK');
|
|
store.get('test-session-id', (err2, data) => {
|
|
if (err2) console.log('GET ERROR:', err2.message);
|
|
else console.log('GET DATA:', JSON.stringify(data));
|
|
});
|
|
}
|
|
});
|
|
} catch (e) {
|
|
console.log('CATCH ERROR:', e.message);
|
|
console.log('STACK:', e.stack);
|
|
}
|