You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/react.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,6 +51,40 @@ root.render(
51
51
);
52
52
```
53
53
54
+
However, exposing API key in the client app isn't the best practice. Alternatively you can use the auth callback to provide the token needed to establish the connection.
55
+
```tsx
56
+
import { AblyProvider } from'ably/react';
57
+
import*asAblyfrom'ably';
58
+
59
+
const BACKEND_URL ="YOUR_BACKEND_URL"
60
+
61
+
const client =newAbly.Realtime({
62
+
authCallback: async (_, callback) => {
63
+
let token:Ably.TokenDetails|null=null;
64
+
65
+
try {
66
+
const response =awaitfetch(BACKEND_URL, {
67
+
method: "POST",
68
+
});
69
+
const token =response.json(); // adjust it based on your backend data structure
0 commit comments