@salesforce/ui-bundle-template-feature-react-authentication 3.0.0 → 3.1.1
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/dist/CHANGELOG.md +17 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/alerts/status-alert.tsx +11 -8
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/input.tsx +1 -1
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/api/userProfileApi.ts +2 -1
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/authenticationConfig.ts +9 -9
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/context/AuthContext.tsx +21 -4
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/forms/auth-form.tsx +15 -1
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/hooks/form.tsx +1 -1
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/layouts/privateRouteLayout.tsx +2 -11
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/pages/ChangePassword.tsx +20 -4
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/pages/ForgotPassword.tsx +19 -4
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/pages/Login.tsx +19 -4
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/pages/Profile.tsx +80 -43
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/pages/Register.tsx +15 -4
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/pages/ResetPassword.tsx +19 -4
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/utils/helpers.ts +15 -52
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/hooks/useAsyncData.ts +67 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/routes.tsx +19 -25
- package/dist/package-lock.json +2 -2
- package/dist/package.json +1 -1
- package/dist/scripts/org-setup.config.json +0 -1
- package/dist/scripts/org-setup.mjs +528 -44
- package/package.json +2 -2
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/layout/card-skeleton.tsx +0 -38
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/layouts/authenticationRouteLayout.tsx +0 -21
|
@@ -8,13 +8,13 @@ import { useAppForm } from "../hooks/form";
|
|
|
8
8
|
import { createDataSDK } from "@salesforce/platform-sdk-data";
|
|
9
9
|
import { ROUTES, AUTH_PLACEHOLDERS } from "../authenticationConfig";
|
|
10
10
|
import { newPasswordSchema } from "../authHelpers";
|
|
11
|
-
import {
|
|
11
|
+
import { ApiError, handleApiResponse } from "../utils/helpers";
|
|
12
12
|
|
|
13
13
|
export default function ResetPassword() {
|
|
14
14
|
const [searchParams] = useSearchParams();
|
|
15
15
|
const token = searchParams.get("token");
|
|
16
16
|
const [success, setSuccess] = useState(false);
|
|
17
|
-
const [submitError, setSubmitError] = useState<
|
|
17
|
+
const [submitError, setSubmitError] = useState<React.ReactNode>(null);
|
|
18
18
|
|
|
19
19
|
const form = useAppForm({
|
|
20
20
|
defaultValues: { newPassword: "", confirmPassword: "" },
|
|
@@ -34,12 +34,27 @@ export default function ResetPassword() {
|
|
|
34
34
|
Accept: "application/json",
|
|
35
35
|
},
|
|
36
36
|
});
|
|
37
|
-
await handleApiResponse(response
|
|
37
|
+
await handleApiResponse(response);
|
|
38
38
|
setSuccess(true);
|
|
39
39
|
// Scroll to top of page after successful submission so user sees it
|
|
40
40
|
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
41
41
|
} catch (err) {
|
|
42
|
-
|
|
42
|
+
console.error("Password reset failed", err);
|
|
43
|
+
if (err instanceof ApiError) {
|
|
44
|
+
setSubmitError(
|
|
45
|
+
err.errors.length === 1 ? (
|
|
46
|
+
err.errors[0]
|
|
47
|
+
) : (
|
|
48
|
+
<ul>
|
|
49
|
+
{err.errors.map((e, i) => (
|
|
50
|
+
<li key={i}>{e}</li>
|
|
51
|
+
))}
|
|
52
|
+
</ul>
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
} else {
|
|
56
|
+
setSubmitError("Password reset failed");
|
|
57
|
+
}
|
|
43
58
|
}
|
|
44
59
|
},
|
|
45
60
|
onSubmitInvalid: () => {},
|
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @param err - The error object (unknown type)
|
|
6
|
-
* @param fallback - Fallback message if error doesn't have a message property
|
|
7
|
-
* @returns The error message string
|
|
2
|
+
* Error thrown when the API returns a non-OK response with structured error messages.
|
|
3
|
+
* The `errors` array contains user-facing messages that are safe to display —
|
|
4
|
+
* backend Apex classes guarantee that system exceptions are never exposed.
|
|
8
5
|
*/
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
export class ApiError extends Error {
|
|
7
|
+
errors: string[];
|
|
8
|
+
constructor(errors: string[]) {
|
|
9
|
+
super(errors[0]);
|
|
10
|
+
this.name = "ApiError";
|
|
11
|
+
this.errors = errors;
|
|
15
12
|
}
|
|
16
|
-
return fallback;
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
/**
|
|
20
16
|
* [Dev Note] Helper to parse the fetch Response.
|
|
21
17
|
* It handles the distinction between success (JSON) and failure (throwing Error).
|
|
22
18
|
*/
|
|
23
|
-
export async function handleApiResponse<T = unknown>(
|
|
24
|
-
response: Response,
|
|
25
|
-
fallbackError: string,
|
|
26
|
-
): Promise<T> {
|
|
19
|
+
export async function handleApiResponse<T = unknown>(response: Response): Promise<T> {
|
|
27
20
|
// 1. Robustness: Handle 204 No Content gracefully
|
|
28
21
|
if (response.status === 204) {
|
|
29
22
|
return {} as T;
|
|
@@ -41,9 +34,11 @@ export async function handleApiResponse<T = unknown>(
|
|
|
41
34
|
}
|
|
42
35
|
|
|
43
36
|
if (!response.ok) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
console.error("API request failed", data);
|
|
38
|
+
if (data?.errors?.length) {
|
|
39
|
+
throw new ApiError(data.errors);
|
|
40
|
+
}
|
|
41
|
+
throw new Error("An unexpected error occurred");
|
|
47
42
|
}
|
|
48
43
|
|
|
49
44
|
return data as T;
|
|
@@ -87,35 +82,3 @@ export function flattenGraphQLRecord<T>(
|
|
|
87
82
|
]),
|
|
88
83
|
) as T;
|
|
89
84
|
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* [Dev Note] Salesforce APIs may return errors as an array or a single object.
|
|
93
|
-
* This helper standardizes the extraction of the error message string.
|
|
94
|
-
*
|
|
95
|
-
* @param data - The response data.
|
|
96
|
-
* @param fallbackError - Fallback error message if response doesn't have a message property
|
|
97
|
-
* @returns The error message string
|
|
98
|
-
*/
|
|
99
|
-
function parseApiResponseError(
|
|
100
|
-
data: any,
|
|
101
|
-
fallbackError: string = "An unknown error occurred",
|
|
102
|
-
): string {
|
|
103
|
-
if (data?.message) {
|
|
104
|
-
return data.message;
|
|
105
|
-
}
|
|
106
|
-
if (data?.error) {
|
|
107
|
-
return data.error;
|
|
108
|
-
}
|
|
109
|
-
if (data?.errors && Array.isArray(data.errors) && data.errors.length > 0) {
|
|
110
|
-
return data.errors.join(" ") || fallbackError;
|
|
111
|
-
}
|
|
112
|
-
if (Array.isArray(data) && data.length > 0) {
|
|
113
|
-
return (
|
|
114
|
-
data
|
|
115
|
-
.map((e) => e?.message)
|
|
116
|
-
.filter(Boolean)
|
|
117
|
-
.join(" ") || fallbackError
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
return fallbackError;
|
|
121
|
-
}
|
package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/hooks/useAsyncData.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
interface UseAsyncDataResult<T> {
|
|
4
|
+
data: T | null;
|
|
5
|
+
loading: boolean;
|
|
6
|
+
error: string | null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Runs an async fetcher on mount and whenever `deps` change.
|
|
11
|
+
* Returns the loading/error/data state. Does not cache — every call
|
|
12
|
+
* to the fetcher hits the source directly.
|
|
13
|
+
*
|
|
14
|
+
* A cleanup flag prevents state updates if the component unmounts
|
|
15
|
+
* or deps change before the fetch completes (avoids React warnings
|
|
16
|
+
* and stale updates from out-of-order responses).
|
|
17
|
+
*/
|
|
18
|
+
export function useAsyncData<T>(
|
|
19
|
+
fetcher: () => Promise<T>,
|
|
20
|
+
deps: React.DependencyList
|
|
21
|
+
): UseAsyncDataResult<T> {
|
|
22
|
+
const [data, setData] = useState<T | null>(null);
|
|
23
|
+
const [loading, setLoading] = useState(true);
|
|
24
|
+
const [error, setError] = useState<string | null>(null);
|
|
25
|
+
const [generation, setGeneration] = useState(0);
|
|
26
|
+
|
|
27
|
+
const fetcherRef = useRef(fetcher);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
fetcherRef.current = fetcher;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Detect dep changes during render to reset loading state and bump generation
|
|
33
|
+
const [prevDeps, setPrevDeps] = useState(deps);
|
|
34
|
+
if (
|
|
35
|
+
deps.length !== prevDeps.length ||
|
|
36
|
+
deps.some((d, i) => d !== prevDeps[i])
|
|
37
|
+
) {
|
|
38
|
+
setPrevDeps(deps);
|
|
39
|
+
setGeneration(g => g + 1);
|
|
40
|
+
if (!loading) setLoading(true);
|
|
41
|
+
if (error !== null) setError(null);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
let cancelled = false;
|
|
46
|
+
|
|
47
|
+
fetcherRef
|
|
48
|
+
.current()
|
|
49
|
+
.then(result => {
|
|
50
|
+
if (!cancelled) setData(result);
|
|
51
|
+
})
|
|
52
|
+
.catch(err => {
|
|
53
|
+
console.error(err);
|
|
54
|
+
if (!cancelled)
|
|
55
|
+
setError(err instanceof Error ? err.message : 'An error occurred');
|
|
56
|
+
})
|
|
57
|
+
.finally(() => {
|
|
58
|
+
if (!cancelled) setLoading(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return () => {
|
|
62
|
+
cancelled = true;
|
|
63
|
+
};
|
|
64
|
+
}, [generation]);
|
|
65
|
+
|
|
66
|
+
return { data, loading, error };
|
|
67
|
+
}
|
|
@@ -8,7 +8,6 @@ import ForgotPassword from "./features/authentication/pages/ForgotPassword";
|
|
|
8
8
|
import ResetPassword from "./features/authentication/pages/ResetPassword";
|
|
9
9
|
import Profile from "./features/authentication/pages/Profile";
|
|
10
10
|
import ChangePassword from "./features/authentication/pages/ChangePassword";
|
|
11
|
-
import AuthenticationRoute from "./features/authentication/layouts/authenticationRouteLayout";
|
|
12
11
|
import PrivateRoute from "./features/authentication/layouts/privateRouteLayout";
|
|
13
12
|
import { ROUTES } from "./features/authentication/authenticationConfig";
|
|
14
13
|
|
|
@@ -27,32 +26,27 @@ export const routes: RouteObject[] = [
|
|
|
27
26
|
element: <NotFound />
|
|
28
27
|
},
|
|
29
28
|
{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
path: ROUTES.RESET_PASSWORD.PATH,
|
|
49
|
-
element: <ResetPassword />,
|
|
50
|
-
handle: { showInNavigation: false, title: ROUTES.RESET_PASSWORD.TITLE }
|
|
51
|
-
}
|
|
52
|
-
]
|
|
29
|
+
path: ROUTES.LOGIN.PATH,
|
|
30
|
+
element: <Login />,
|
|
31
|
+
handle: { showInNavigation: false, label: "Login", title: ROUTES.LOGIN.TITLE }
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
path: ROUTES.REGISTER.PATH,
|
|
35
|
+
element: <Register />,
|
|
36
|
+
handle: { showInNavigation: false, title: ROUTES.REGISTER.TITLE }
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
path: ROUTES.FORGOT_PASSWORD.PATH,
|
|
40
|
+
element: <ForgotPassword />,
|
|
41
|
+
handle: { showInNavigation: false, title: ROUTES.FORGOT_PASSWORD.TITLE }
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
path: ROUTES.RESET_PASSWORD.PATH,
|
|
45
|
+
element: <ResetPassword />,
|
|
46
|
+
handle: { showInNavigation: false, title: ROUTES.RESET_PASSWORD.TITLE }
|
|
53
47
|
},
|
|
54
48
|
{
|
|
55
|
-
element: <PrivateRoute
|
|
49
|
+
element: <PrivateRoute />,
|
|
56
50
|
children: [
|
|
57
51
|
{
|
|
58
52
|
path: ROUTES.PROFILE.PATH,
|
package/dist/package-lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/webapp-template-base-sfdx-project-experimental",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@salesforce/webapp-template-base-sfdx-project-experimental",
|
|
9
|
-
"version": "3.
|
|
9
|
+
"version": "3.1.1",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@lwc/eslint-plugin-lwc": "^3.3.0",
|
package/dist/package.json
CHANGED