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:
parent
9762a935cb
commit
41cc9f54cd
1 changed files with 16 additions and 1 deletions
|
|
@ -29,11 +29,22 @@ const GET_USER_DATA = gql`
|
||||||
|
|
||||||
const Main = () => {
|
const Main = () => {
|
||||||
const [location, navigate] = useLocation()
|
const [location, navigate] = useLocation()
|
||||||
const { wizardTested, userData, setUserData } = useContext(AppContext)
|
const { wizardTested, userData, setUserData} = useContext(AppContext)
|
||||||
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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue