moved lifetime to config
This commit is contained in:
parent
6566bb4403
commit
c4ee8fc372
|
|
@ -37,6 +37,8 @@ class Config {
|
||||||
readonly is_debug: boolean = process.env.NODE_ENV != "production"
|
readonly is_debug: boolean = process.env.NODE_ENV != "production"
|
||||||
readonly is_production: boolean = process.env.NODE_ENV == "production"
|
readonly is_production: boolean = process.env.NODE_ENV == "production"
|
||||||
|
|
||||||
|
private _session_timeout: number = 15 * 60 * 1000
|
||||||
|
|
||||||
get log_dir(): string {
|
get log_dir(): string {
|
||||||
return this._log_dir
|
return this._log_dir
|
||||||
}
|
}
|
||||||
|
|
@ -44,6 +46,8 @@ class Config {
|
||||||
return this._log_to_file_when_debug
|
return this._log_to_file_when_debug
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get session_timeout(): number { return this._session_timeout }
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._log_dir = resolve_env_to_path(process.env.APP_LOG_DIR, "./data/logs")
|
this._log_dir = resolve_env_to_path(process.env.APP_LOG_DIR, "./data/logs")
|
||||||
this._log_to_file_when_debug = resolve_env_to_boolean(process.env.LOG_TO_FILE_WHEN_DEBUG, false)
|
this._log_to_file_when_debug = resolve_env_to_boolean(process.env.LOG_TO_FILE_WHEN_DEBUG, false)
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,10 @@ import { Prisma } from "@prisma/client"
|
||||||
|
|
||||||
import { ArgumentError, DuplicateError } from "$lib/errors"
|
import { ArgumentError, DuplicateError } from "$lib/errors"
|
||||||
|
|
||||||
|
import Config from "$lib/server/config"
|
||||||
import Log from "$lib/server/log"
|
import Log from "$lib/server/log"
|
||||||
import db from "$lib/server/database"
|
import db from "$lib/server/database"
|
||||||
|
|
||||||
const SESSION_LIFETIME = 15 * 60 * 1000
|
|
||||||
|
|
||||||
export type User = Prisma.UserGetPayload<Prisma.UserDefaultArgs>
|
export type User = Prisma.UserGetPayload<Prisma.UserDefaultArgs>
|
||||||
|
|
||||||
export interface SessionData {
|
export interface SessionData {
|
||||||
|
|
@ -120,7 +119,7 @@ class UserMgmt {
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = Crypto.randomBytes(32).toBase64()
|
const token = Crypto.randomBytes(32).toBase64()
|
||||||
const session_info = this._cache.add(user, token, new Date(), new Date(Date.now() + SESSION_LIFETIME))
|
const session_info = this._cache.add(user, token, new Date(), new Date(Date.now() + Config.session_timeout))
|
||||||
|
|
||||||
return session_info
|
return session_info
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue