Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved usability with single OAuth2 session #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

edwinvdpol
Copy link
Contributor

I use this library a lot for my apps. All just use 1 single OAuth2 client and every time I want to check if there are any OAuth2 devices available (for timer etc), I need to use the boiler template below because everywhere the sessionId is needed:

class App extends OAuth2App {
  ...

  // Return client devices
  async getClientDevices() {
    const sessions = this.getSavedOAuth2Sessions();

    if (blank(sessions)) {
      return [];
    }

    const sessionId = Object.keys(sessions)[0];

    return this.getOAuth2Devices({ sessionId });
  }

  ...
}

In this PR, the now required sessionId parameter for the getOAuth2Devices() function is optional, and will grap the first session key by default if available.

I also added a few functions which are shortcuts to already existing functionalities, but make it a bit more pleasant to work with.

There should not be any breaking changes as far as I can see.

Let me know what you think!

-- Edwin

@WeeJeWel
Copy link
Contributor

WeeJeWel commented Nov 6, 2024

I don't know about your usecase, but wouldn't it be more logical to loop the devices (driver.getDevices()) and use their OAuth2Session somehow?

@edwinvdpol
Copy link
Contributor Author

Currently, interacting with OAuth2 devices requires retrieving the session ID each time, leading to duplicated and, in my view, unnecessary code for what should be a straightforward task.

This PR simplifies the process, allowing you to disable all devices at once if, for example, an external API becomes unavailable or is down.

The hasOAuth2Devices function quickly checks for available OAuth2 devices. If none are found, it can stop an update timer in app.js, as there would be nothing to update. The timer can restart automatically when a device is added. In my apps, many functions depend on the API state, impacting all devices.

My focus is on creating short, simple functions to keep my code clean and avoid unnecessary boilerplate. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants