@vtex/faststore-plugin-buyer-portal 1.1.116-poc-3 → 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-3",
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,8 +3,6 @@ import { useEffect, useState } from "react";
3
3
  import { useRouter } from "next/router";
4
4
 
5
5
  import { authClient } from "../clients/Auth";
6
- import { ClientContext } from "../utils";
7
-
8
6
  export type UseAuthResult = {
9
7
  isAuthenticated: boolean | null;
10
8
  isLoading: boolean;
@@ -16,7 +14,7 @@ export type UseAuthResult = {
16
14
  *
17
15
  * @returns Object containing authentication status and loading state
18
16
  */
19
- export const useAuth = (clientContext: ClientContext): UseAuthResult => {
17
+ export const useAuth = (cookie: string): UseAuthResult => {
20
18
  const [isAuthenticated, setIsAuthenticated] = useState<boolean | null>(null);
21
19
  const [isLoading, setIsLoading] = useState(true);
22
20
  const router = useRouter();
@@ -26,7 +24,7 @@ export const useAuth = (clientContext: ClientContext): UseAuthResult => {
26
24
  setIsLoading(true);
27
25
 
28
26
  try {
29
- const hasAccess = await authClient.validateAccess(clientContext);
27
+ const hasAccess = await authClient.validateAccess({ cookie });
30
28
 
31
29
  if (!hasAccess) {
32
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;
@@ -36,12 +37,12 @@ const loaderFunction = async (
36
37
  const { orgUnitId } = data.query;
37
38
 
38
39
  const { cookie, userId, ...clientContext } = await getClientContext(data);
39
- console.log(">>> Org Unit Loader", cookie);
40
40
 
41
41
  return {
42
42
  data: {
43
43
  orgUnitId,
44
44
  userId,
45
+ cookie,
45
46
  },
46
47
  context: {
47
48
  clientContext: { cookie, userId, ...clientContext },
@@ -56,7 +57,6 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
56
57
 
57
58
  const OrgUnitDetailsPage = ({
58
59
  data,
59
- context,
60
60
  hasError,
61
61
  error,
62
62
  }: OrgUnitDetailsPageData) => {
@@ -64,8 +64,8 @@ const OrgUnitDetailsPage = ({
64
64
  return <ErrorTabsLayout error={error} />;
65
65
  }
66
66
 
67
- const { isAuthenticated, isLoading } = useAuth(context.clientContext);
68
- console.log(">> Org Unit Details, auth", isAuthenticated, isLoading);
67
+ const { isAuthenticated, isLoading } = useAuth(data.cookie);
68
+ console.log(">> Context", data.cookie);
69
69
 
70
70
  if (isLoading || isAuthenticated === null) {
71
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 },
@@ -57,12 +59,12 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
57
59
  redirectToError: true,
58
60
  });
59
61
 
60
- const ProfilePage = ({ data, context, hasError, error }: ProfilePageData) => {
62
+ const ProfilePage = ({ data, hasError, error }: ProfilePageData) => {
61
63
  if (hasError) {
62
64
  return <ErrorTabsLayout error={error} />;
63
65
  }
64
66
 
65
- const { isAuthenticated, isLoading } = useAuth(context.clientContext);
67
+ const { isAuthenticated, isLoading } = useAuth(data.cookie);
66
68
 
67
69
  if (isLoading || isAuthenticated === null) {
68
70
  return <PageLoader />;