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
Add authenticator function used at reconnection (#650)
When the SDK reconnect to Kuzzle, it trigger the `reconnected` event. The Realtime controller will try to resubscribe when this event is triggered.
If the token had expired, then the Realtime controller will try to resubscribe with no authentication and thus the subscriptions request may fail.
This PR include a new `authenticator` property, this property should contain a function that authenticate the SDK (with `auth.login` for example).
The SDK will call the function before emitting the reconnected event, if the SDK was authenticated and cannot re-authenticate then the `reconnected` event will not be emitted and the SDK will be in the `disconnected` state.
A new `reconnectionError` has been added and is triggered when the reconnection has failed
|`offlineQueueLoader`| <pre>function</pre> | Called before dequeuing requests after exiting offline mode, to add items at the beginning of the offline queue |
34
-
|`queueFilter`| <pre>function</pre> | Custom function called during offline mode to filter queued requests on-the-fly |
35
-
|`queueMaxSize`| <pre>number</pre> | Number of maximum requests kept during offline mode|
36
-
|`queueTTL`| <pre>number</pre> | Time a queued request is kept during offline mode, in milliseconds |
37
-
|`replayInterval`| <pre>number</pre> | Delay between each replayed requests |
38
-
|`volatile`| <pre>object</pre> | Common volatile data, will be sent to all future requests |
|`offlineQueueLoader`| <pre>function</pre> | Called before dequeuing requests after exiting offline mode, to add items at the beginning of the offline queue |
35
+
|`queueFilter`| <pre>function</pre> | Custom function called during offline mode to filter queued requests on-the-fly |
36
+
|`queueMaxSize`| <pre>number</pre> | Number of maximum requests kept during offline mode |
37
+
|`queueTTL`| <pre>number</pre> | Time a queued request is kept during offline mode, in milliseconds |
38
+
|`replayInterval`| <pre>number</pre> | Delay between each replayed requests |
39
+
|`volatile`| <pre>object</pre> | Common volatile data, will be sent to all future requests |
40
+
41
+
### authenticator
42
+
43
+
The `authenticator` property can be set to a function returning a promise.
44
+
45
+
This function will be called after a successful reconnection if the current authentication token is not valid anymore.
46
+
47
+
This function has to authenticate the SDK. It can be a call to [auth.login](/sdk/js/7/controllers/auth/login) for example.
If the `authenticator` function fail to authenticate the SDK, then the `reconnected` event is never emitted and a `reconnectionError` event is emitted.
The returned (or resolved) array must contain objects, each with the following properties:
51
68
52
-
| Property | Type | Description |
53
-
|---|---|---|
54
-
|`query`| <pre>object</pre> | Object representing the request that is about to be sent to Kuzzle, following the [Kuzzle API](/core/2/guides/main-concepts/querying) format |
55
-
|`reject`| <pre>function</pre> | A [Promise.reject](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject) function |
56
-
|`resolve`| <pre>function</pre> | A [Promise.resolve](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve) function |
|`query`| <pre>object</pre>| Object representing the request that is about to be sent to Kuzzle, following the [Kuzzle API](/core/2/guides/main-concepts/querying) format |
72
+
|`reject`| <pre>function</pre> | A [Promise.reject](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject) function|
73
+
|`resolve`| <pre>function</pre> | A [Promise.resolve](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve) function |
Copy file name to clipboardExpand all lines: doc/7/essentials/offline-tools/index.md
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,33 @@ order: 400
11
11
The Kuzzle SDK provides a set of properties that helps your application to be resilient to the loss of network connection
12
12
during its lifespan.
13
13
14
+
## Authentication after reconnection
15
+
16
+
When the SDK reconnect, the authentication token may not be valid anymore.
17
+
18
+
It's possible to set the [authenticator](/sdk/js/7/core-classes/kuzzle/properties#authenticator) function to allows the SDK to re-authenticate after a successful reconnection.
19
+
20
+
<details><summary>Example to automatically re-authenticate on reconnection</summary>
These properties can be set in the `options` object when [instantiating a new SDK](/sdk/js/7/core-classes/kuzzle/constructor#arguments).
@@ -77,6 +104,10 @@ A read-only `number` specifying the time in milliseconds between different recon
77
104
78
105
Default value: *Depends on the Protocol*
79
106
107
+
### reconnectionError
108
+
109
+
Emitted when the SDK reconnect to Kuzzle and does not have a valid authentication token or can't renew it with the [authenticator](/sdk/js/7/core-classes/kuzzle/properties#authenticator) function.
0 commit comments