fix: skip auth queries on public pages (register/login)

The GET_USER_DATA query includes restrictionLevel which has @auth directive.
This was causing authentication errors on /register and /login pages where
users are not yet authenticated.

Solution:
- Skip the GraphQL query when on public pages (/register or /login)
- Use useEffect to set loading=false immediately for public pages
- Add onError handler to gracefully handle query failures

Fixes authentication error: 'Message: Authentication failed, Path: restrictionLevel'

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
padreug 2025-11-17 20:51:15 +01:00
parent 9762a935cb
commit 41cc9f54cd

View file

@ -33,7 +33,18 @@ const Main = () => {
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
const [restrictionLevel, setRestrictionLevel] = useState(null) const [restrictionLevel, setRestrictionLevel] = useState(null)
// Skip auth queries on unauthenticated pages (like /register and /login)
const isPublicPage = location.startsWith('/register') || location.startsWith('/login')
// Set loading to false immediately for public pages
React.useEffect(() => {
if (isPublicPage) {
setLoading(false)
}
}, [isPublicPage])
useQuery(GET_USER_DATA, { useQuery(GET_USER_DATA, {
skip: isPublicPage,
onCompleted: userResponse => { onCompleted: userResponse => {
if (!userData && userResponse?.userData) { if (!userData && userResponse?.userData) {
setUserData(userResponse.userData) setUserData(userResponse.userData)
@ -43,6 +54,10 @@ const Main = () => {
} }
setLoading(false) setLoading(false)
}, },
onError: () => {
// If query fails, just mark as not loading
setLoading(false)
},
}) })
const sidebar = hasSidebar(location) const sidebar = hasSidebar(location)