@salesforce/webapp-template-feature-react-authentication-experimental 1.45.1 → 1.46.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 CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.46.1](https://github.com/salesforce-experience-platform-emu/webapps/compare/v1.46.0...v1.46.1) (2026-02-20)
7
+
8
+ **Note:** Version bump only for package @salesforce/webapp-template-base-sfdx-project-experimental
9
+
10
+
11
+
12
+
13
+
14
+ # [1.46.0](https://github.com/salesforce-experience-platform-emu/webapps/compare/v1.45.1...v1.46.0) (2026-02-20)
15
+
16
+ **Note:** Version bump only for package @salesforce/webapp-template-base-sfdx-project-experimental
17
+
18
+
19
+
20
+
21
+
6
22
  ## [1.45.1](https://github.com/salesforce-experience-platform-emu/webapps/compare/v1.45.0...v1.45.1) (2026-02-20)
7
23
 
8
24
  **Note:** Version bump only for package @salesforce/webapp-template-base-sfdx-project-experimental
@@ -0,0 +1,21 @@
1
+ import { createDataSDK, type DataSDK } from "@salesforce/sdk-data";
2
+
3
+ type FetchableSDK = DataSDK & { fetch: typeof fetch };
4
+
5
+ let sdkPromise: Promise<FetchableSDK> | null = null;
6
+
7
+ /**
8
+ * Returns a singleton DataSDK instance with a guaranteed fetch method.
9
+ * Lazily initialized on first call; subsequent calls return the same instance.
10
+ */
11
+ export function getDataSDK(): Promise<FetchableSDK> {
12
+ if (!sdkPromise) {
13
+ sdkPromise = createDataSDK().then((sdk) => {
14
+ if (!sdk.fetch) {
15
+ throw new Error("DataSDK fetch is not available on this surface.");
16
+ }
17
+ return sdk as FetchableSDK;
18
+ });
19
+ }
20
+ return sdkPromise;
21
+ }
@@ -1,10 +1,10 @@
1
1
  import { useState } from "react";
2
2
  import { Link } from "react-router";
3
3
  import { z } from "zod";
4
- import { uiApiClient } from "@salesforce/webapp-experimental/api";
5
4
  import { CenteredPageLayout } from "../components/layout/centered-page-layout";
6
5
  import { AuthForm } from "../components/forms/auth-form";
7
6
  import { useAppForm } from "../hooks/form";
7
+ import { getDataSDK } from "../lib/data-sdk";
8
8
  import { ROUTES, AUTH_PLACEHOLDERS } from "../components/auth/authenticationConfig";
9
9
  import { newPasswordSchema } from "../components/auth/authHelpers";
10
10
  import { handleApiResponse, getErrorMessage } from "../utils/helpers";
@@ -28,13 +28,18 @@ export default function ChangePassword() {
28
28
  try {
29
29
  // [Dev Note] Custom Apex Endpoint: /auth/change-password
30
30
  // You must ensure this Apex class exists in your org
31
- const response = await uiApiClient.post(
32
- `${window.location.origin}/sfdcapi/services/apexrest/auth/change-password`,
33
- {
31
+ const sdk = await getDataSDK();
32
+ const response = await sdk.fetch("/sfdcapi/services/apexrest/auth/change-password", {
33
+ method: "POST",
34
+ body: JSON.stringify({
34
35
  currentPassword: formFieldValues.currentPassword,
35
36
  newPassword: formFieldValues.newPassword,
37
+ }),
38
+ headers: {
39
+ "Content-Type": "application/json",
40
+ Accept: "application/json",
36
41
  },
37
- );
42
+ });
38
43
  await handleApiResponse(response, "Password change failed");
39
44
  setSuccess(true);
40
45
  form.reset();
@@ -1,9 +1,9 @@
1
1
  import { useState } from "react";
2
2
  import { z } from "zod";
3
- import { uiApiClient } from "@salesforce/webapp-experimental/api";
4
3
  import { CenteredPageLayout } from "../components/layout/centered-page-layout";
5
4
  import { AuthForm } from "../components/forms/auth-form";
6
5
  import { useAppForm } from "../hooks/form";
6
+ import { getDataSDK } from "../lib/data-sdk";
7
7
  import { ROUTES, AUTH_PLACEHOLDERS } from "../components/auth/authenticationConfig";
8
8
  import { handleApiResponse, getErrorMessage } from "../utils/helpers";
9
9
 
@@ -24,10 +24,15 @@ export default function ForgotPassword() {
24
24
  try {
25
25
  // [Dev Note] Custom Apex Endpoint: /auth/forgot-password
26
26
  // You must ensure this Apex class exists in your org
27
- const response = await uiApiClient.post(
28
- `${window.location.origin}/sfdcapi/services/apexrest/auth/forgot-password`,
29
- { username: value.username.trim() },
30
- );
27
+ const sdk = await getDataSDK();
28
+ const response = await sdk.fetch("/sfdcapi/services/apexrest/auth/forgot-password", {
29
+ method: "POST",
30
+ body: JSON.stringify({ username: value.username.trim() }),
31
+ headers: {
32
+ "Content-Type": "application/json",
33
+ Accept: "application/json",
34
+ },
35
+ });
31
36
  await handleApiResponse(response, "Failed to send reset link");
32
37
  setSuccess(true);
33
38
  } catch (err) {
@@ -1,10 +1,10 @@
1
1
  import { useState } from "react";
2
2
  import { useNavigate, useSearchParams, Link } from "react-router";
3
3
  import { z } from "zod";
4
- import { uiApiClient } from "@salesforce/webapp-experimental/api";
5
4
  import { CenteredPageLayout } from "../components/layout/centered-page-layout";
6
5
  import { AuthForm } from "../components/forms/auth-form";
7
6
  import { useAppForm } from "../hooks/form";
7
+ import { getDataSDK } from "../lib/data-sdk";
8
8
  import { ROUTES } from "../components/auth/authenticationConfig";
9
9
  import { emailSchema, getStartUrl, type AuthResponse } from "../components/auth/authHelpers";
10
10
  import { handleApiResponse, getErrorMessage } from "../utils/helpers";
@@ -26,18 +26,23 @@ export default function Login() {
26
26
  setSubmitError(null);
27
27
  try {
28
28
  // [Dev Note] Salesforce Integration:
29
- // We use uiApiClient.post with an absolute path to call the custom Apex REST auth endpoint.
30
- // "/sfdcapi/services/apexrest/auth/login" refers to a custom Apex Class exposed as a REST resource.
29
+ // We use the Data SDK fetch to make an authenticated (or guest) call to Salesforce.
30
+ // "/sfdcapi/services/apexrest/auth/login" refers to a custom Apex REST resource.
31
31
  // You must ensure this Apex class exists in your org and handles the login logic
32
32
  // (e.g., creating a session or returning a token).
33
- const response = await uiApiClient.post(
34
- `${window.location.origin}/sfdcapi/services/apexrest/auth/login`,
35
- {
33
+ const sdk = await getDataSDK();
34
+ const response = await sdk.fetch("/sfdcapi/services/apexrest/auth/login", {
35
+ method: "POST",
36
+ body: JSON.stringify({
36
37
  email: value.email.trim().toLowerCase(),
37
38
  password: value.password,
38
39
  startUrl: getStartUrl(searchParams),
40
+ }),
41
+ headers: {
42
+ "Content-Type": "application/json",
43
+ Accept: "application/json",
39
44
  },
40
- );
45
+ });
41
46
  const result = await handleApiResponse<AuthResponse>(response, "Login failed");
42
47
  if (result?.redirectUrl) {
43
48
  // Hard navigate to the URL which establishes the server session cookie
@@ -1,10 +1,10 @@
1
1
  import { useState } from "react";
2
2
  import { useNavigate, useSearchParams } from "react-router";
3
3
  import { z } from "zod";
4
- import { uiApiClient } from "@salesforce/webapp-experimental/api";
5
4
  import { CenteredPageLayout } from "../components/layout/centered-page-layout";
6
5
  import { AuthForm } from "../components/forms/auth-form";
7
6
  import { useAppForm } from "../hooks/form";
7
+ import { getDataSDK } from "../lib/data-sdk";
8
8
  import { ROUTES, AUTH_PLACEHOLDERS } from "../components/auth/authenticationConfig";
9
9
  import {
10
10
  emailSchema,
@@ -46,13 +46,21 @@ export default function Register() {
46
46
  onSubmit: async ({ value: formFieldValues }) => {
47
47
  setSubmitError(null);
48
48
  try {
49
- // [Dev Note] Calls the custom Apex REST endpoint for user registration.
50
- // Ensure your Apex logic handles duplicate checks and user creation (e.g., Site.createExternalUser).
49
+ // [Dev Note] Salesforce Integration:
50
+ // We use the Data SDK fetch to make an authenticated (or guest) call to Salesforce.
51
+ // "/sfdcapi/services/apexrest/auth/register" refers to a custom Apex Class exposed as a REST resource.
52
+ // You must ensure this Apex class exists in your org and handles registration
53
+ // (e.g., duplicate checks and user creation such as Site.createExternalUser).
51
54
  const { confirmPassword, ...request } = formFieldValues;
52
- const response = await uiApiClient.post(
53
- `${window.location.origin}/sfdcapi/services/apexrest/auth/register`,
54
- { request },
55
- );
55
+ const sdk = await getDataSDK();
56
+ const response = await sdk.fetch("/sfdcapi/services/apexrest/auth/register", {
57
+ method: "POST",
58
+ body: JSON.stringify({ request }),
59
+ headers: {
60
+ "Content-Type": "application/json",
61
+ Accept: "application/json",
62
+ },
63
+ });
56
64
  const result = await handleApiResponse<AuthResponse>(response, "Registration failed");
57
65
  if (result?.redirectUrl) {
58
66
  // Hard navigate to the URL which logs the new user in
@@ -1,11 +1,11 @@
1
1
  import { useState } from "react";
2
2
  import { Link, useSearchParams } from "react-router";
3
- import { uiApiClient } from "@salesforce/webapp-experimental/api";
4
3
  import { CardLayout } from "../components/layout/card-layout";
5
4
  import { CenteredPageLayout } from "../components/layout/centered-page-layout";
6
5
  import { AuthForm } from "../components/forms/auth-form";
7
6
  import { StatusAlert } from "../components/alerts/status-alert";
8
7
  import { useAppForm } from "../hooks/form";
8
+ import { getDataSDK } from "../lib/data-sdk";
9
9
  import { ROUTES, AUTH_PLACEHOLDERS } from "../components/auth/authenticationConfig";
10
10
  import { newPasswordSchema } from "../components/auth/authHelpers";
11
11
  import { handleApiResponse, getErrorMessage } from "../utils/helpers";
@@ -25,10 +25,15 @@ export default function ResetPassword() {
25
25
  try {
26
26
  // [Dev Note] Custom Apex Endpoint: /auth/reset-password
27
27
  // You must ensure this Apex class exists in your org
28
- const response = await uiApiClient.post(
29
- `${window.location.origin}/services/apexrest/auth/reset-password`,
30
- { token, newPassword: value.newPassword },
31
- );
28
+ const sdk = await getDataSDK();
29
+ const response = await sdk.fetch("/sfdcapi/services/apexrest/auth/reset-password", {
30
+ method: "POST",
31
+ body: JSON.stringify({ token, newPassword: value.newPassword }),
32
+ headers: {
33
+ "Content-Type": "application/json",
34
+ Accept: "application/json",
35
+ },
36
+ });
32
37
  await handleApiResponse(response, "Password reset failed");
33
38
  setSuccess(true);
34
39
  // Scroll to top of page after successful submission so user sees it
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/webapp-template-base-sfdx-project-experimental",
3
- "version": "1.45.1",
3
+ "version": "1.46.1",
4
4
  "description": "Base SFDX project template",
5
5
  "private": true,
6
6
  "files": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/webapp-template-feature-react-authentication-experimental",
3
- "version": "1.45.1",
3
+ "version": "1.46.1",
4
4
  "description": "Authentication feature for web applications",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "",
@@ -16,7 +16,7 @@
16
16
  "clean": "rm -rf dist"
17
17
  },
18
18
  "devDependencies": {
19
- "@salesforce/webapp-experimental": "^1.45.1",
19
+ "@salesforce/webapp-experimental": "^1.46.1",
20
20
  "@tanstack/react-form": "^1.27.7",
21
21
  "@types/react": "^19.2.7",
22
22
  "@types/react-dom": "^19.2.3",
@@ -40,5 +40,5 @@
40
40
  }
41
41
  }
42
42
  },
43
- "gitHead": "091ae5ef0b936a7d51ca59a06c10ae4c301022c4"
43
+ "gitHead": "9d00ba69ff791509b15fdf2f36c10700d612ca5b"
44
44
  }