feat: Add saveLoginPassword option to control password saving behavior in browser for offline auth on servers

This commit is contained in:
Vitaly Turovsky 2025-09-08 05:38:16 +03:00
commit 06dc3cb033
3 changed files with 27 additions and 4 deletions

View file

@ -84,6 +84,7 @@ export const defaultOptions = {
localServerOptions: {
gameMode: 1
} as any,
saveLoginPassword: 'prompt' as 'prompt' | 'never' | 'always',
preferLoadReadonly: false,
experimentalClientSelfReload: false,
remoteSoundsSupport: false,

View file

@ -550,6 +550,16 @@ export const guiOptionsScheme: {
return <Category>Server Connection</Category>
},
},
{
saveLoginPassword: {
tooltip: 'Controls whether to save login passwords for servers in this browser memory.',
values: [
'prompt',
'always',
'never'
]
},
},
{
custom () {
const { serversAutoVersionSelect } = useSnapshot(options)

View file

@ -73,16 +73,28 @@ export default () => {
}
const builtinHandled = tryHandleBuiltinCommand(message)
if (getServerIndex() !== undefined && (message.startsWith('/login') || message.startsWith('/register'))) {
showNotification('Click here to save your password in browser for auto-login', undefined, false, undefined, () => {
if (getServerIndex() !== undefined && (message.startsWith('/login') || message.startsWith('/register')) && options.saveLoginPassword !== 'never') {
const savePassword = () => {
let hadPassword = false
updateLoadedServerData((server) => {
server.autoLogin ??= {}
const password = message.split(' ')[1]
hadPassword = !!server.autoLogin[bot.username]
server.autoLogin[bot.username] = password
return { ...server }
})
hideNotification()
})
if (options.saveLoginPassword === 'always') {
const message = hadPassword ? 'Password updated in browser for auto-login' : 'Password saved in browser for auto-login'
showNotification(message, undefined, false, undefined)
} else {
hideNotification()
}
}
if (options.saveLoginPassword === 'prompt') {
showNotification('Click here to save your password in browser for auto-login', undefined, false, undefined, savePassword)
} else {
savePassword()
}
notificationProxy.id = 'auto-login'
const listener = () => {
hideNotification()