fix: logout was ineffective on /path1 after a basic-authentication login on /path2

Massimo Melina committed Jun 6, 2024 at 16:03 UTC 11907c256b52d4f105a8cbe1d76e5a5cb2d849a7
1 file changed +5 -4
frontend/src/login.ts
+5 -4
@@ -30,14 +30,15 @@ async function login(username:string, password:string) {
30 const sessionRefresher = makeSessionRefresher(state)
31 sessionRefresher(getHFS().session)
32
33 -export function logout(){
34 - return apiCall('logout', {}, { modal: working }).catch(res => {
35 - if (res.code !== HTTP_UNAUTHORIZED) // we expect this error code
33 +export function logout() {
34 + // browsers (chrome125) memorize basic-auth credentials based on the path. Returning 401 on /~/api won't be effective on other paths, so we make a call "here" (as doing the same on / wasn't effective).
35 + return fetch('?get=logout').then(res => {
36 + if (res.status !== HTTP_UNAUTHORIZED) // we expect this error code
37 throw res
38 state.username = ''
39 reloadList()
40 toast(t`Logged out`, 'success')
40 - })
41 + }).finally(working())
42 }
43
44 export let closeLoginDialog: undefined | (() => void)