Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 5 additions & 20 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@
"type": "string"
}
},
"required": [
"rel",
"href"
]
"required": ["rel", "href"]
},
"description": "admin/store.faviconLinks.description"
},
Expand Down Expand Up @@ -261,10 +258,7 @@
"description": "admin/store.advancedSettings.customHeader.value.description"
}
},
"required": [
"key",
"value"
]
"required": ["key", "value"]
}
},
"useDefaultBrowserNavigation": {
Expand All @@ -282,18 +276,14 @@
{
"properties": {
"requiresAuthorization": {
"enum": [
false
]
"enum": [false]
}
}
},
{
"properties": {
"requiresAuthorization": {
"enum": [
true
]
"enum": [true]
},
"b2bEnabled": {
"title": "admin/store.b2benabled.title",
Expand All @@ -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"
}
56 changes: 38 additions & 18 deletions react/ProfileChallenge.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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<SessionResponse>()
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) => {
Expand All @@ -53,12 +75,10 @@ interface Props {
}

const ProfileChallenge: FC<Props> = ({ 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)

Expand Down
84 changes: 0 additions & 84 deletions react/__tests__/ProfileChallenge.test.tsx

This file was deleted.

7 changes: 0 additions & 7 deletions react/graphql/getAuthenticatedUser.graphql

This file was deleted.

4 changes: 0 additions & 4 deletions react/typings/graphql.d.ts

This file was deleted.

Loading