Skip to content

Commit b3e48f8

Browse files
authored
fix(ui): logout type error when user is null during locale switch (#13514)
### What? Prevent a `TypeError: Cannot read properties of null (reading 'collection')` in the admin UI when switching locales by hardening `AuthProvider.logOut`. ### Why? During locale transitions, user can briefly be null. The existing code used `user.collection` unguarded ### How? - Use `userSlug` over `user.collection`. - Always clear local auth in a `finally` block (`setNewUser(null)`, `revokeTokenAndExpire()`), regardless of request outcome. Fixes #13313 --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1211093549155962
1 parent f44e276 commit b3e48f8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/ui/src/providers/Auth/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,17 @@ export function AuthProvider({
192192

193193
const logOut = useCallback(async () => {
194194
try {
195-
await requests.post(`${serverURL}${apiRoute}/${user.collection}/logout`)
196-
setNewUser(null)
197-
revokeTokenAndExpire()
195+
if (user && user.collection) {
196+
await requests.post(`${serverURL}${apiRoute}/${user.collection}/logout`)
197+
}
198198
return true
199199
} catch (e) {
200200
toast.error(`Logging out failed: ${e.message}`)
201201
return false
202+
} finally {
203+
// Always clear local auth state
204+
setNewUser(null)
205+
revokeTokenAndExpire()
202206
}
203207
}, [apiRoute, revokeTokenAndExpire, serverURL, setNewUser, user])
204208

0 commit comments

Comments
 (0)