@vtex/faststore-plugin-buyer-portal 1.1.116-poc-2 → 1.1.116-poc-4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/faststore-plugin-buyer-portal",
3
- "version": "1.1.116-poc-2",
3
+ "version": "1.1.116-poc-4",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -57,7 +57,7 @@ export const OrgUnitsDetailsLayout = ({
57
57
  loading = isOrgUnitLoading || isContractsLoading || isUserLoading;
58
58
  const isMobile = useMediaQuery(QUERY_TABLET);
59
59
 
60
- const isSingleContract = contracts.length <= 1;
60
+ const isSingleContract = !contracts ? true : contracts.length <= 1;
61
61
 
62
62
  const { orgUnit: userUnit } = useOrgUnitByUser(userId);
63
63
 
@@ -3,9 +3,6 @@ import { useEffect, useState } from "react";
3
3
  import { useRouter } from "next/router";
4
4
 
5
5
  import { authClient } from "../clients/Auth";
6
-
7
- import { useBuyerPortal } from "./useBuyerPortal";
8
-
9
6
  export type UseAuthResult = {
10
7
  isAuthenticated: boolean | null;
11
8
  isLoading: boolean;
@@ -17,8 +14,7 @@ export type UseAuthResult = {
17
14
  *
18
15
  * @returns Object containing authentication status and loading state
19
16
  */
20
- export const useAuth = (): UseAuthResult => {
21
- const { clientContext } = useBuyerPortal();
17
+ export const useAuth = (cookie: string): UseAuthResult => {
22
18
  const [isAuthenticated, setIsAuthenticated] = useState<boolean | null>(null);
23
19
  const [isLoading, setIsLoading] = useState(true);
24
20
  const router = useRouter();
@@ -28,7 +24,7 @@ export const useAuth = (): UseAuthResult => {
28
24
  setIsLoading(true);
29
25
 
30
26
  try {
31
- const hasAccess = await authClient.validateAccess(clientContext);
27
+ const hasAccess = await authClient.validateAccess({ cookie });
32
28
 
33
29
  if (!hasAccess) {
34
30
  router.push("/");
@@ -18,6 +18,7 @@ export type OrgUnitDetailsPageData = {
18
18
  data: {
19
19
  orgUnitId: string;
20
20
  userId: string;
21
+ cookie: string;
21
22
  };
22
23
  context: {
23
24
  clientContext: ClientContext;
@@ -41,6 +42,7 @@ const loaderFunction = async (
41
42
  data: {
42
43
  orgUnitId,
43
44
  userId,
45
+ cookie,
44
46
  },
45
47
  context: {
46
48
  clientContext: { cookie, userId, ...clientContext },
@@ -62,7 +64,8 @@ const OrgUnitDetailsPage = ({
62
64
  return <ErrorTabsLayout error={error} />;
63
65
  }
64
66
 
65
- const { isAuthenticated, isLoading } = useAuth();
67
+ const { isAuthenticated, isLoading } = useAuth(data.cookie);
68
+ console.log(">> Context", data.cookie);
66
69
 
67
70
  if (isLoading || isAuthenticated === null) {
68
71
  return <PageLoader />;
@@ -17,6 +17,7 @@ export type ProfilePageData = {
17
17
  contractId: string;
18
18
  orgUnitId: string;
19
19
  userId: string;
20
+ cookie: string;
20
21
  };
21
22
  context: {
22
23
  clientContext: ClientContext;
@@ -43,6 +44,7 @@ const loaderFunction = async (
43
44
  contractId,
44
45
  orgUnitId,
45
46
  userId,
47
+ cookie,
46
48
  },
47
49
  context: {
48
50
  clientContext: { cookie, userId, ...clientContext },
@@ -62,7 +64,7 @@ const ProfilePage = ({ data, hasError, error }: ProfilePageData) => {
62
64
  return <ErrorTabsLayout error={error} />;
63
65
  }
64
66
 
65
- const { isAuthenticated, isLoading } = useAuth();
67
+ const { isAuthenticated, isLoading } = useAuth(data.cookie);
66
68
 
67
69
  if (isLoading || isAuthenticated === null) {
68
70
  return <PageLoader />;