@vtex/faststore-plugin-buyer-portal 1.3.3 → 1.3.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/CHANGELOG.md +8 -1
- package/package.json +1 -1
- package/src/features/shared/components/Error/error.scss +6 -0
- package/src/features/shared/types/AuthRouteProps.ts +15 -2
- package/src/features/shared/utils/constants.ts +1 -1
- package/src/features/shared/utils/withAuth.tsx +19 -7
- package/src/features/shared/utils/withAuthLoader.ts +15 -3
- package/src/features/shared/utils/withAuthProvider.tsx +15 -5
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.3.4] - 2025-10-16
|
|
11
|
+
|
|
12
|
+
- Error boundary:
|
|
13
|
+
- Updating the authentication loader to provide detailed error context.
|
|
14
|
+
|
|
10
15
|
## [1.3.3] - 2025-10-16
|
|
11
16
|
|
|
12
17
|
### Added
|
|
@@ -115,10 +120,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
115
120
|
- Add CHANGELOG file
|
|
116
121
|
- Add README file
|
|
117
122
|
|
|
118
|
-
[unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/1.3.
|
|
123
|
+
[unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/1.3.4...HEAD
|
|
119
124
|
[1.2.3]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.2.2...1.2.3
|
|
120
125
|
[1.2.3]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.2.3
|
|
121
126
|
[1.2.4]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.2.4
|
|
122
127
|
[1.3.2]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.3.2
|
|
123
128
|
|
|
124
129
|
[1.3.3]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.3.3
|
|
130
|
+
|
|
131
|
+
[1.3.4]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.3.4
|
package/package.json
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
padding: var(--fs-spacing-4);
|
|
34
34
|
border-radius: var(--fs-border-radius-medium);
|
|
35
35
|
position: relative;
|
|
36
|
+
max-width: 100%;
|
|
36
37
|
|
|
37
38
|
[data-fs-bp-error-details-type] {
|
|
38
39
|
position: absolute;
|
|
@@ -56,6 +57,7 @@
|
|
|
56
57
|
font-weight: var(--fs-text-weight-medium);
|
|
57
58
|
color: #e2e2e2;
|
|
58
59
|
text-wrap: wrap;
|
|
60
|
+
overflow-wrap: break-word;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
[data-fs-bp-error-details-stack] {
|
|
@@ -63,12 +65,16 @@
|
|
|
63
65
|
margin: var(--fs-spacing-4) 0;
|
|
64
66
|
font-weight: var(--fs-text-weight-medium);
|
|
65
67
|
text-wrap: wrap;
|
|
68
|
+
max-width: 100%;
|
|
69
|
+
overflow-wrap: break-word;
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
[data-fs-bp-error-details-component] {
|
|
69
73
|
font-size: var(--fs-text-size-2);
|
|
70
74
|
font-weight: var(--fs-text-weight-medium);
|
|
71
75
|
text-wrap: wrap;
|
|
76
|
+
overflow-wrap: break-word;
|
|
77
|
+
max-width: 100%;
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
80
|
}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
+
import { ErrorBoundaryProps } from "../components/ErrorBoundary/types";
|
|
1
2
|
import { ClientContext } from "../utils";
|
|
2
3
|
|
|
3
4
|
export type AuthRouteProps<T> =
|
|
4
|
-
| {
|
|
5
|
-
|
|
5
|
+
| {
|
|
6
|
+
authorized: true;
|
|
7
|
+
data: T;
|
|
8
|
+
clientContext: ClientContext;
|
|
9
|
+
hasError?: boolean;
|
|
10
|
+
error?: ErrorBoundaryProps;
|
|
11
|
+
}
|
|
12
|
+
| {
|
|
13
|
+
authorized: false;
|
|
14
|
+
hasError?: boolean;
|
|
15
|
+
error?: ErrorBoundaryProps;
|
|
16
|
+
data?: T;
|
|
17
|
+
clientContext?: ClientContext;
|
|
18
|
+
};
|
|
@@ -2,30 +2,42 @@ import { useEffect, type ComponentType } from "react";
|
|
|
2
2
|
|
|
3
3
|
import { useRouter } from "next/router";
|
|
4
4
|
|
|
5
|
+
import { ErrorBoundaryProps } from "../components/ErrorBoundary/types";
|
|
6
|
+
|
|
5
7
|
import type { AuthRouteProps } from "../types";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* HOC that checks only for authorization
|
|
9
11
|
*/
|
|
10
12
|
export const withAuth = <T extends Record<string, unknown>>(
|
|
11
|
-
Component: ComponentType<T>
|
|
13
|
+
Component: ComponentType<T & { hasError?: boolean }>
|
|
12
14
|
) => {
|
|
13
|
-
return function AuthenticatedComponent(
|
|
15
|
+
return function AuthenticatedComponent(
|
|
16
|
+
props: AuthRouteProps<T> & {
|
|
17
|
+
hasError?: boolean;
|
|
18
|
+
error?: ErrorBoundaryProps;
|
|
19
|
+
}
|
|
20
|
+
) {
|
|
14
21
|
const router = useRouter();
|
|
15
22
|
|
|
16
23
|
useEffect(() => {
|
|
17
24
|
// If not authorized, reload the page
|
|
18
|
-
if (!props?.authorized) {
|
|
25
|
+
if (!props?.authorized && !props?.hasError) {
|
|
19
26
|
router.reload();
|
|
20
27
|
}
|
|
21
|
-
}, [props?.authorized, router]);
|
|
28
|
+
}, [props?.authorized, props?.hasError, router]);
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
if (!props?.authorized) {
|
|
30
|
+
if (!props?.authorized && !props?.hasError && !props?.error) {
|
|
25
31
|
return null;
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
// If authorized, render the component with the data
|
|
29
|
-
return
|
|
35
|
+
return (
|
|
36
|
+
<Component
|
|
37
|
+
{...(props.data as T)}
|
|
38
|
+
hasError={props?.hasError}
|
|
39
|
+
error={props?.error}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
30
42
|
};
|
|
31
43
|
};
|
|
@@ -37,11 +37,23 @@ export const withAuthLoader = async <T>(
|
|
|
37
37
|
} catch (error) {
|
|
38
38
|
console.error("Auth validation failed:", error);
|
|
39
39
|
|
|
40
|
-
data.res?.writeHead(302, { Location: "/" });
|
|
41
|
-
data.res?.end();
|
|
42
|
-
|
|
43
40
|
return {
|
|
44
41
|
authorized: false,
|
|
42
|
+
hasError: true,
|
|
43
|
+
error: {
|
|
44
|
+
error: {
|
|
45
|
+
message: (error as Error).message,
|
|
46
|
+
name: (error as Error).name,
|
|
47
|
+
stack: (error as Error).stack || undefined,
|
|
48
|
+
},
|
|
49
|
+
extra: {
|
|
50
|
+
query: data.query,
|
|
51
|
+
},
|
|
52
|
+
tags: {
|
|
53
|
+
component: "AuthLoader",
|
|
54
|
+
errorType: "auth_error",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
45
57
|
};
|
|
46
58
|
}
|
|
47
59
|
};
|
|
@@ -3,6 +3,7 @@ import { useEffect, type ComponentType } from "react";
|
|
|
3
3
|
import { useRouter } from "next/router";
|
|
4
4
|
|
|
5
5
|
import { BuyerPortalProvider } from "../components";
|
|
6
|
+
import { ErrorBoundaryProps } from "../components/ErrorBoundary/types";
|
|
6
7
|
|
|
7
8
|
import type { AuthRouteProps } from "../types";
|
|
8
9
|
import type { ClientContext } from "./getClientContext";
|
|
@@ -13,7 +14,12 @@ import type { ClientContext } from "./getClientContext";
|
|
|
13
14
|
export const withAuthProvider = <T,>(
|
|
14
15
|
Component: ComponentType<T & { clientContext: ClientContext }>
|
|
15
16
|
) => {
|
|
16
|
-
return function WrappedPage(
|
|
17
|
+
return function WrappedPage(
|
|
18
|
+
props: AuthRouteProps<T> & {
|
|
19
|
+
hasError?: boolean;
|
|
20
|
+
error?: ErrorBoundaryProps;
|
|
21
|
+
}
|
|
22
|
+
) {
|
|
17
23
|
const router = useRouter();
|
|
18
24
|
|
|
19
25
|
useEffect(() => {
|
|
@@ -23,14 +29,18 @@ export const withAuthProvider = <T,>(
|
|
|
23
29
|
}
|
|
24
30
|
}, [props?.authorized, router]);
|
|
25
31
|
|
|
26
|
-
|
|
27
|
-
if (!props?.authorized) {
|
|
32
|
+
if (!props?.authorized && !props?.hasError && !props?.error) {
|
|
28
33
|
return null;
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
return (
|
|
32
|
-
<BuyerPortalProvider
|
|
33
|
-
|
|
37
|
+
<BuyerPortalProvider
|
|
38
|
+
clientContext={props?.clientContext as ClientContext}
|
|
39
|
+
>
|
|
40
|
+
<Component
|
|
41
|
+
{...(props.data as T)}
|
|
42
|
+
clientContext={props?.clientContext as ClientContext}
|
|
43
|
+
/>
|
|
34
44
|
</BuyerPortalProvider>
|
|
35
45
|
);
|
|
36
46
|
};
|