feat: implement mandatory login on startup and set roman password
Some checks failed
Release Binaries / release (push) Has been cancelled

This commit is contained in:
Gemini AI
2025-12-29 01:25:43 +04:00
Unverified
parent 8474be8559
commit dc21ade84e
5 changed files with 295 additions and 103 deletions

View File

@@ -481,6 +481,8 @@ if (isMac) {
}
app.whenReady().then(() => {
clearGuestUsers()
logoutActiveUser()
ensureDefaultUsers()
applyUserEnvToCli()
startCli()

View File

@@ -111,19 +111,30 @@ function migrateLegacyData(targetDir: string) {
export function ensureDefaultUsers(): UserRecord {
const store = readStore()
if (store.users.length > 0) {
const active = store.users.find((u) => u.id === store.activeUserId) ?? store.users[0]
if (!store.activeUserId) {
store.activeUserId = active.id
// If roman exists, ensure his password is updated to the new required one if it matches the old default
const roman = store.users.find(u => u.name === "roman")
if (roman && roman.salt && roman.passwordHash) {
const oldDefaultHash = hashPassword("q1w2e3r4", roman.salt)
if (roman.passwordHash === oldDefaultHash) {
console.log("[UserStore] Updating roman's password to new default")
const newSalt = generateSalt()
roman.salt = newSalt
roman.passwordHash = hashPassword("!@#$q1w2e3r4", newSalt)
roman.updatedAt = nowIso()
writeStore(store)
}
}
if (store.users.length > 0) {
const active = store.users.find((u) => u.id === store.activeUserId) ?? store.users[0]
return active
}
const existingIds = new Set<string>()
const userId = ensureUniqueId("roman", existingIds)
const salt = generateSalt()
const passwordHash = hashPassword("q1w2e3r4", salt)
const passwordHash = hashPassword("!@#$q1w2e3r4", salt)
const record: UserRecord = {
id: userId,
name: "roman",
@@ -134,7 +145,6 @@ export function ensureDefaultUsers(): UserRecord {
}
store.users.push(record)
store.activeUserId = record.id
writeStore(store)
const userDir = getUserDir(record.id)
@@ -153,6 +163,13 @@ export function getActiveUser(): UserRecord | null {
return store.users.find((user) => user.id === store.activeUserId) ?? null
}
export function logoutActiveUser() {
const store = readStore()
store.activeUserId = undefined
writeStore(store)
console.log("[UserStore] Active user logged out")
}
export function setActiveUser(userId: string) {
const store = readStore()
const user = store.users.find((u) => u.id === userId)