Added login bypass
This commit is contained in:
parent
16b5aba457
commit
d7dcbb3560
|
|
@ -1,3 +1,4 @@
|
||||||
|
import Bun from "bun"
|
||||||
import path from "node:path"
|
import path from "node:path"
|
||||||
|
|
||||||
const to_absolute_path = (p: string): string => {
|
const to_absolute_path = (p: string): string => {
|
||||||
|
|
@ -40,6 +41,8 @@ class Config {
|
||||||
private _session_timeout: number = 15 * 60 * 1000
|
private _session_timeout: number = 15 * 60 * 1000
|
||||||
private _session_refresh_grace: number = 5 * 60 * 1000 // time until expiration
|
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 {
|
get log_dir(): string {
|
||||||
return this._log_dir
|
return this._log_dir
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
export default _manager
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue