Fix authentification check in public trust center
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -102,6 +102,7 @@ function PublicTrustCenterContent() {
|
|||||||
const [data, setData] = useState<PublicTrustCenterData | null>(null);
|
const [data, setData] = useState<PublicTrustCenterData | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<Error | null>(null);
|
const [error, setError] = useState<Error | null>(null);
|
||||||
|
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||||
|
|
||||||
const organizationName = data?.trustCenterBySlug?.organization?.name;
|
const organizationName = data?.trustCenterBySlug?.organization?.name;
|
||||||
usePageTitle(organizationName ? `${organizationName} - Trust Center` : "Trust Center");
|
usePageTitle(organizationName ? `${organizationName} - Trust Center` : "Trust Center");
|
||||||
@@ -113,6 +114,7 @@ function PublicTrustCenterContent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
setIsAuthenticated(false);
|
||||||
|
|
||||||
fetch(buildEndpoint("/api/trust/v1/graphql"), {
|
fetch(buildEndpoint("/api/trust/v1/graphql"), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -129,6 +131,10 @@ function PublicTrustCenterContent() {
|
|||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then((result: GraphQLResponse<PublicTrustCenterData>) => {
|
.then((result: GraphQLResponse<PublicTrustCenterData>) => {
|
||||||
|
const accessDeniedErrors = result.errors?.filter((error: GraphQLError) =>
|
||||||
|
error.message.includes('access denied')
|
||||||
|
) || [];
|
||||||
|
|
||||||
const nonAuthErrors = result.errors?.filter((error: GraphQLError) =>
|
const nonAuthErrors = result.errors?.filter((error: GraphQLError) =>
|
||||||
!error.message.includes('access denied')
|
!error.message.includes('access denied')
|
||||||
) || [];
|
) || [];
|
||||||
@@ -137,6 +143,7 @@ function PublicTrustCenterContent() {
|
|||||||
throw new Error(nonAuthErrors[0].message);
|
throw new Error(nonAuthErrors[0].message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setIsAuthenticated(accessDeniedErrors.length === 0);
|
||||||
setData(result.data || null);
|
setData(result.data || null);
|
||||||
})
|
})
|
||||||
.catch(setError)
|
.catch(setError)
|
||||||
@@ -176,10 +183,6 @@ function PublicTrustCenterContent() {
|
|||||||
const vendors = trustCenterBySlug.vendors.edges
|
const vendors = trustCenterBySlug.vendors.edges
|
||||||
.map(edge => edge.node);
|
.map(edge => edge.node);
|
||||||
|
|
||||||
const isAuthenticated = audits.some((audit: Audit) =>
|
|
||||||
audit.report?.downloadUrl || audit.reportUrl
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PublicTrustCenterLayout
|
<PublicTrustCenterLayout
|
||||||
organizationName={organization.name}
|
organizationName={organization.name}
|
||||||
|
|||||||
Reference in New Issue
Block a user