Remove function-style constructor from Keycloak JS (#19912)

This commit is contained in:
Jon Koops 2023-04-24 14:24:33 +02:00 committed by GitHub
parent 4bac7a66ef
commit 5cfa4bedfd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 16 deletions

View file

@ -2,6 +2,10 @@
With this release, we have removed the legacy Promise API methods from the Keycloak JS adapter. This means that calling `.success()` and `.error()` on promises returned from the adapter is no longer possible.
= Keycloak JS adapter must be instantiated with the `new` operator
In a previous release we started to actively log deprecation warnings when the Keycloak JS adapter is constructed without the `new` operator. Starting this release doing so will throw an exception instead. This is to align with the expected behavior of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes[JavaScript classes], which will allow further refactoring of the adapter in the future.
= Export and Import perform an automatic build
In previous releases, the `export` and `import` commands required a `build` command to be run first.

View file

@ -332,11 +332,6 @@ export interface KeycloakRoles {
*/
export type KeycloakInstance = Keycloak;
/**
* @deprecated Construct a Keycloak instance using the `new` keyword instead.
*/
declare function Keycloak(config?: KeycloakConfig | string): Keycloak;
/**
* A client for the Keycloak authentication server.
* @see {@link https://keycloak.gitbooks.io/securing-client-applications-guide/content/topics/oidc/javascript-adapter.html|Keycloak JS adapter documentation}

View file

@ -21,19 +21,9 @@ if (typeof Promise === 'undefined') {
throw Error('Keycloak requires an environment that supports Promises. Make sure that you include the appropriate polyfill.');
}
var loggedConstructorDeprecation = false;
function logConstructorDeprecation() {
if (!loggedConstructorDeprecation) {
loggedConstructorDeprecation = true;
console.warn('[KEYCLOAK] Instantiation using the `Keycloak` function has been deprecated and support will be removed in future versions. Use the `new` operator to create an instance instead.');
}
}
function Keycloak (config) {
if (!(this instanceof Keycloak)) {
logConstructorDeprecation();
return new Keycloak(config);
throw new Error("The 'Keycloak' constructor must be invoked with 'new'.")
}
var kc = this;