Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customise login expiry #177

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ export interface Config {
windowMs?: number;
max?: number;
};

/*
The amount of time before the session expires and a user must log in again.
*/
sessionTimeout?: {
days: number,
hours: number,
minutes: number
}
}

// default config:
Expand Down
8 changes: 8 additions & 0 deletions server/src/passport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ChatServer from './index';
import { config } from './config';

const secret = config.authSecret;
const sessionTimeout = config.sessionTimeout;

export function configurePassport(context: ChatServer) {
const SQLiteStore = createSQLiteSessionStore(session);
Expand Down Expand Up @@ -51,6 +52,13 @@ export function configurePassport(context: ChatServer) {
secret,
resave: false,
saveUninitialized: false,
cookie: {
maxAge: sessionTimeout
? (sessionTimeout.days * (1000 * 60 * 60 * 24))
+ (sessionTimeout.hours * (1000 * 60 * 60))
+ (sessionTimeout.minutes * (1000 * 60))
: undefined
},
store: sessionStore as any,
}));
context.app.use(passport.authenticate('session'));
Expand Down