From 41cc9f54cdc20ab75d7dec5ac44d15ca5bb64a1f Mon Sep 17 00:00:00 2001 From: padreug Date: Mon, 17 Nov 2025 20:51:15 +0100 Subject: [PATCH] fix: skip auth queries on public pages (register/login) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- packages/admin-ui/src/Main.jsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/admin-ui/src/Main.jsx b/packages/admin-ui/src/Main.jsx index e162b96..4600cee 100644 --- a/packages/admin-ui/src/Main.jsx +++ b/packages/admin-ui/src/Main.jsx @@ -29,11 +29,22 @@ const GET_USER_DATA = gql` const Main = () => { const [location, navigate] = useLocation() - const { wizardTested, userData, setUserData } = useContext(AppContext) + const { wizardTested, userData, setUserData} = useContext(AppContext) const [loading, setLoading] = useState(true) 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, { + skip: isPublicPage, onCompleted: userResponse => { if (!userData && userResponse?.userData) { setUserData(userResponse.userData) @@ -43,6 +54,10 @@ const Main = () => { } setLoading(false) }, + onError: () => { + // If query fails, just mark as not loading + setLoading(false) + }, }) const sidebar = hasSidebar(location)