fix: accessing a protected resource with the wrong account didn't show any error, just login dialogs

Massimo Melina committed Jan 18, 2023 at 22:34 UTC f04f2e815d4982d81a34359a04e5585aec001975
1 file changed +7 -2
frontend/src/useFetchList.ts
+7 -2
@@ -7,6 +7,7 @@ import { DirEntry, DirList, usePath } from './BrowseFiles'
7 import _ from 'lodash'
8 import { subscribeKey } from 'valtio/utils'
9 import { useIsMounted } from 'usehooks-ts'
10 +import { alertDialog } from './dialog'
11
12 const API = 'file_list'
13
@@ -18,6 +19,7 @@ export default function useFetchList() {
19 const lastReq = useRef<any>()
20 const isMounted = useIsMounted()
21 useEffect(()=>{
22 + if (snap.loginRequired) return
23 const previous = lastPath.current
24 lastPath.current = desiredPath
25 if (previous !== desiredPath) {
@@ -63,7 +65,7 @@ export default function useFetchList() {
65 lastReq.current = undefined
66 return
67 case 'msg':
66 - data.forEach((entry: any) => {
68 + data.forEach(async (entry: any) => {
69 if (entry.props)
70 return Object.assign(state, _.pick(entry.props, ['can_upload']))
71 if (entry.add)
@@ -77,6 +79,8 @@ export default function useFetchList() {
79 if (error) {
80 state.stopSearch?.()
81 state.error = (ERRORS as any)[error] || String(error)
82 + if (error === 401)
83 + await alertDialog("This account has no access, try another", 'warning')
84 state.loginRequired = error === 401
85 lastReq.current = null
86 return
@@ -97,7 +101,8 @@ export default function useFetchList() {
101 }
102
103 const ERRORS = {
100 - 404: "Not found"
104 + 401: "Unauthorized",
105 + 404: "Not found",
106 }
107
108 export function reloadList() {