From 237be691593d0cab0e9d803f28afd8975a59f365 Mon Sep 17 00:00:00 2001 From: Iago Espinoza Date: Mon, 6 Apr 2026 16:21:55 -0300 Subject: [PATCH 1/2] revert 627 --- CHANGELOG.md | 2 +- manifest.json | 27 ++----- react/ProfileChallenge.tsx | 56 ++++++++++----- react/__tests__/ProfileChallenge.test.tsx | 84 ---------------------- react/graphql/getAuthenticatedUser.graphql | 7 -- react/typings/graphql.d.ts | 4 -- 6 files changed, 45 insertions(+), 135 deletions(-) delete mode 100644 react/__tests__/ProfileChallenge.test.tsx delete mode 100644 react/graphql/getAuthenticatedUser.graphql delete mode 100644 react/typings/graphql.d.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 59b65282..0f113fa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] -## [2.146.0] - 2025-12-18 +## [2.146.0] - 2025-12-18 [YANKED] ### Added diff --git a/manifest.json b/manifest.json index 136aa4f5..dec71547 100644 --- a/manifest.json +++ b/manifest.json @@ -35,7 +35,7 @@ "vtex.rich-text": "0.x", "vtex.native-types": "0.x", "vtex.telemarketing": "2.x", - "vtex.shipping-option-components": "1.x" + "vtex.shipping-option-components": "2.x" }, "settingsSchema": { "title": "admin/store.title", @@ -90,10 +90,7 @@ "type": "string" } }, - "required": [ - "rel", - "href" - ] + "required": ["rel", "href"] }, "description": "admin/store.faviconLinks.description" }, @@ -261,10 +258,7 @@ "description": "admin/store.advancedSettings.customHeader.value.description" } }, - "required": [ - "key", - "value" - ] + "required": ["key", "value"] } }, "useDefaultBrowserNavigation": { @@ -282,18 +276,14 @@ { "properties": { "requiresAuthorization": { - "enum": [ - false - ] + "enum": [false] } } }, { "properties": { "requiresAuthorization": { - "enum": [ - true - ] + "enum": [true] }, "b2bEnabled": { "title": "admin/store.b2benabled.title", @@ -314,12 +304,7 @@ "b2bEnabled": { "ui:disabled": "true" }, - "ui:order": [ - "storeName", - "requiresAuthorization", - "b2bEnabled", - "*" - ] + "ui:order": ["storeName", "requiresAuthorization", "b2bEnabled", "*"] }, "$schema": "https://raw.githubusercontent.com/vtex/node-vtex-api/master/gen/manifest.schema" } diff --git a/react/ProfileChallenge.tsx b/react/ProfileChallenge.tsx index 105c65a7..8be53d40 100644 --- a/react/ProfileChallenge.tsx +++ b/react/ProfileChallenge.tsx @@ -1,8 +1,13 @@ -import React, { useEffect, FC } from 'react' -import { useQuery } from 'react-apollo' -import { useRuntime, canUseDOM, Loading } from 'vtex.render-runtime' +import React, { useState, useEffect, FC } from 'react' +import { + useRuntime, + canUseDOM, + Loading, + SessionResponse, + Session, +} from 'vtex.render-runtime' -import getAuthenticatedUser from './graphql/getAuthenticatedUser.graphql' +import { getSession } from './modules/session' const loginPath = '/login' @@ -16,18 +21,35 @@ const getLocation = () => pathName: window.location.pathname, } : { - url: (global as any).__pathname__, // eslint-disable-line @typescript-eslint/no-explicit-any - pathName: (global as any).__pathname__, // eslint-disable-line @typescript-eslint/no-explicit-any + url: (global as any).__pathname__, + pathName: (global as any).__pathname__, } -const useStoreGraphqlSession = () => { - const shouldRunQuery = canUseDOM +const useSessionResponse = () => { + const [session, setSession] = useState() + const sessionPromise = getSession() - const { data, loading, error } = useQuery(getAuthenticatedUser, { - skip: !shouldRunQuery, - }) + useEffect(() => { + if (!sessionPromise) { + return + } + + sessionPromise.then(sessionResponse => { + const response = sessionResponse.response as SessionResponse + + setSession(response) + }) + }, [sessionPromise]) - return { data, loading, error } + return session +} + +function hasSession(session: SessionResponse | undefined): session is Session { + return ( + session !== undefined && + session.type !== 'Unauthorized' && + session.type !== 'Forbidden' + ) } const useLoginRedirect = (isLoggedIn: boolean | null, page: string) => { @@ -53,12 +75,10 @@ interface Props { } const ProfileChallenge: FC = ({ children, page }) => { - const storeGraphqlSession = useStoreGraphqlSession() - - const isLoggedIn = - storeGraphqlSession.loading === false - ? !!storeGraphqlSession.data?.authenticatedUser?.id - : null + const session = useSessionResponse() + const isLoggedIn = hasSession(session) + ? session.namespaces?.profile?.isAuthenticated?.value === 'true' + : null useLoginRedirect(isLoggedIn, page) diff --git a/react/__tests__/ProfileChallenge.test.tsx b/react/__tests__/ProfileChallenge.test.tsx deleted file mode 100644 index ffce9730..00000000 --- a/react/__tests__/ProfileChallenge.test.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import React from 'react' -import { useQuery } from 'react-apollo' -import { render, screen, waitFor } from '@vtex/test-tools/react' -import { useRuntime } from 'vtex.render-runtime' - -import ProfileChallenge from '../ProfileChallenge' - -jest.mock('react-apollo', () => ({ - useQuery: jest.fn(), -})) -jest.mock('vtex.render-runtime', () => ({ - useRuntime: jest.fn(), - canUseDOM: true, - Loading: () =>
Loading...
, // eslint-disable-line react/display-name -})) - -describe('ProfileChallenge', () => { - const mockAssign = jest.fn() - beforeAll(() => { - Object.defineProperty(window, 'location', { - value: { - assign: mockAssign, - pathname: '/', - search: '', - hash: '', - }, - writable: true, - }) - }) - beforeEach(() => { - jest.clearAllMocks() - ;(useRuntime as jest.Mock).mockReturnValue({ rootPath: '' }) - }) - - it('shows loading while query is loading', () => { - ;(useQuery as jest.Mock).mockReturnValue({ loading: true }) - render(child) - expect(screen.getByText('Loading...')).toBeInTheDocument() - }) - - it('renders children if user is authenticated', async () => { - ;(useQuery as jest.Mock) - .mockReturnValueOnce({ loading: true }) - .mockReturnValue({ - loading: false, - data: { authenticatedUser: { userId: 'abc123' } }, - }) - const { rerender } = render( - - child - - ) - rerender( - - child - - ) - await waitFor(() => { - expect(screen.queryByText('Loading...')).toBeNull() - // Current behavior is redirecting; assert redirect to keep test green - expect(mockAssign).toHaveBeenCalledWith('/login?returnUrl=%2F') - }) - }) - - it('redirects to login if not authenticated', async () => { - ;(useQuery as jest.Mock).mockReturnValue({ - loading: false, - data: { authenticatedUser: null }, - }) - render(child) - await waitFor(() => { - expect(mockAssign).toHaveBeenCalledWith('/login?returnUrl=%2F') - }) - }) - - it('does not redirect on login page', () => { - ;(useQuery as jest.Mock).mockReturnValue({ - loading: false, - data: { authenticatedUser: null }, - }) - render(child) - expect(mockAssign).not.toHaveBeenCalled() - }) -}) diff --git a/react/graphql/getAuthenticatedUser.graphql b/react/graphql/getAuthenticatedUser.graphql deleted file mode 100644 index 74383b83..00000000 --- a/react/graphql/getAuthenticatedUser.graphql +++ /dev/null @@ -1,7 +0,0 @@ -query getAuthenticatedUser { - authenticatedUser @context(provider: "vtex.store-graphql") { - id - email - name - } -} \ No newline at end of file diff --git a/react/typings/graphql.d.ts b/react/typings/graphql.d.ts deleted file mode 100644 index 097c85de..00000000 --- a/react/typings/graphql.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module '*.graphql' { - const value: any - export default value -} From 82bc0f03285f63dce76d5eda23cbb0f948a484ca Mon Sep 17 00:00:00 2001 From: Iago Espinoza Date: Mon, 6 Apr 2026 16:22:59 -0300 Subject: [PATCH 2/2] revert 627 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index dec71547..1ca39a48 100644 --- a/manifest.json +++ b/manifest.json @@ -35,7 +35,7 @@ "vtex.rich-text": "0.x", "vtex.native-types": "0.x", "vtex.telemarketing": "2.x", - "vtex.shipping-option-components": "2.x" + "vtex.shipping-option-components": "1.x" }, "settingsSchema": { "title": "admin/store.title",