feat: Add saveLoginPassword option to control password saving behavior in browser for offline auth on servers
This commit is contained in:
parent
c4097975bf
commit
06dc3cb033
3 changed files with 27 additions and 4 deletions
|
|
@ -84,6 +84,7 @@ export const defaultOptions = {
|
|||
localServerOptions: {
|
||||
gameMode: 1
|
||||
} as any,
|
||||
saveLoginPassword: 'prompt' as 'prompt' | 'never' | 'always',
|
||||
preferLoadReadonly: false,
|
||||
experimentalClientSelfReload: false,
|
||||
remoteSoundsSupport: false,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue