Added login bypass

This commit is contained in:
Patrick 2025-10-16 15:07:04 +02:00
parent 16b5aba457
commit d7dcbb3560
2 changed files with 44 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import Bun from "bun"
import path from "node:path"
const to_absolute_path = (p: string): string => {
@ -40,6 +41,8 @@ class Config {
private _session_timeout: number = 15 * 60 * 1000
private _session_refresh_grace: number = 5 * 60 * 1000 // time until expiration
readonly bypass_login = this.is_debug && process.env.BYPASS_LOGIN == "true"
get log_dir(): string {
return this._log_dir
}

View File

@ -158,6 +158,46 @@ class UserMgmt {
}
}
const _manager = new UserMgmt()
class _LOGIN_BYPASS_Mgmt extends UserMgmt {
global_session: SessionData | null = null
constructor() {
super()
db.user.findFirst().then((user) => {
if (!user) {
return
}
this.global_session = {
token: "",
user: user,
expires: new Date(8640000000000000), // Max Time
issued: new Date()
}
})
}
async login(): Promise<SessionData | null> {
if (!this.global_session) {
const user = await db.user.findFirst()
if (user) {
this.global_session = {
token: "",
user: user,
expires: new Date(8640000000000000), // Max Time
issued: new Date()
}
}
}
return this.global_session
}
async session_login(): Promise<SessionData | null> {
return this.login()
}
}
const _manager = (Config.is_debug && Config.bypass_login) ? new _LOGIN_BYPASS_Mgmt() : new UserMgmt()
export default _manager