Skip to content

Bind public methods to class instance#204

Merged
jonkoops merged 1 commit intokeycloak:mainfrom
jonkoops:bound-public-methods
Nov 4, 2025
Merged

Bind public methods to class instance#204
jonkoops merged 1 commit intokeycloak:mainfrom
jonkoops:bound-public-methods

Conversation

@jonkoops
Copy link
Copy Markdown
Contributor

@jonkoops jonkoops commented Nov 4, 2025

Binds all public methods directly to the Keycloak instance using arrow function to prevent scoping issues. Although this would prevent binding public methods, which users might rely on (as a hack, nothing officially supported), this re-enables a much more widespread and common use-case to destructuring methods:

const { login } = new Keycloak();

Closes #202

@jonkoops jonkoops requested a review from Copilot November 4, 2025 13:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR converts public instance methods in the Keycloak class from traditional method syntax to arrow function class field syntax. This ensures that method references maintain proper this binding when passed as callbacks or used in contexts where they might lose their class instance context.

Key changes:

  • Converted 15 public methods from traditional syntax to arrow function class fields
  • Methods affected include init, login, logout, register, and various token/user management methods
  • Private methods (prefixed with #) remain unchanged with traditional method syntax

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/keycloak.js
Comment thread lib/keycloak.js
Copy link
Copy Markdown
Contributor

@rmartinc rmartinc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jonkoops! Tested with the account console and it works as before. The only problem I see if some was doing a manual bind (or similar) before, but I don't expect that.

@jonkoops jonkoops merged commit fd1fca4 into keycloak:main Nov 4, 2025
10 checks passed
@jonkoops jonkoops deleted the bound-public-methods branch April 22, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Release 26.2.1 contains breaking changes

3 participants