feb20de2ef
* Update release notes for 21.1 * Update docs/documentation/release_notes/topics/21_1_0.adoc Co-authored-by: Pedro Igor <pigor.craveiro@gmail.com> * Update docs/documentation/upgrading/topics/keycloak/changes-21_1_0.adoc Co-authored-by: Jon Koops <jonkoops@gmail.com> * Update docs/documentation/release_notes/topics/21_1_0.adoc Co-authored-by: Jon Koops <jonkoops@gmail.com> * Update docs/documentation/upgrading/topics/keycloak/changes-21_1_0.adoc Co-authored-by: Jon Koops <jonkoops@gmail.com> --------- Co-authored-by: Pedro Igor <pigor.craveiro@gmail.com> Co-authored-by: Jon Koops <jonkoops@gmail.com>
40 lines
1.4 KiB
Text
40 lines
1.4 KiB
Text
= Legacy Promise API removed from Keycloak JS adapter
|
|
|
|
The legacy Promise API methods have been removed from the Keycloak JS adapter. This means that calling `.success()` and `.error()` on promises returned from the adapter is no longer possible. Instead standardized Promise methods such as https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then[`.then()`] and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch[`.catch()`] should be used.
|
|
|
|
*Before:*
|
|
```javascript
|
|
const keycloak = new Keycloak();
|
|
|
|
keycloak.init()
|
|
.success(function(authenticated) {
|
|
alert(authenticated ? 'authenticated' : 'not authenticated');
|
|
}).error(function() {
|
|
alert('failed to initialize');
|
|
});
|
|
```
|
|
|
|
*After:*
|
|
```javascript
|
|
const keycloak = new Keycloak();
|
|
|
|
keycloak.init()
|
|
.then(function(authenticated) {
|
|
alert(authenticated ? 'authenticated' : 'not authenticated');
|
|
}).catch(function() {
|
|
alert('failed to initialize');
|
|
});
|
|
```
|
|
|
|
Or alternatively, when using the https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await[`await`] keyword to unwrap these promises:
|
|
|
|
```javascript
|
|
const keycloak = new Keycloak();
|
|
|
|
try {
|
|
const authenticated = await keycloak.init();
|
|
alert(authenticated ? 'authenticated' : 'not authenticated');
|
|
} catch (error) {
|
|
alert('failed to initialize');
|
|
}
|
|
```
|