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

fix(auth): bind handleUnauthenticated to correct context #4120

Conversation

Sofien-Sellami
Copy link
Contributor

@Sofien-Sellami Sofien-Sellami commented May 13, 2024

Context

The issue was that the handleUnauthenticated function passed as a prop to the PrivateRoute component was a regular function, which caused a scope issue with this. In this function, this referred to the global object instead of the instance of userAuthenticationService.

-public handleUnauthenticated() { return this.serviceImplementation._handleUnauthenticated(); }
The value of this was undefined instead of referring to the instance of userAuthenticationService.

Changes & Results

I modified the code to pass an arrow function instead of a regular function to the PrivateRoute component. This way, this is correctly bound to the context of userAuthenticationService.

Before:

-<PrivateRoute handleUnauthenticated={userAuthenticationService.handleUnauthenticated}>

After:

-<PrivateRoute handleUnauthenticated={() => userAuthenticationService.handleUnauthenticated()}>

Testing

Checklist

PR

  • [] My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

  • [] My code has been well-documented (function documentation, inline comments,
    etc.)

Public Documentation Updates

  • [] The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • [] OS:
  • [] Node version:
  • [] Browser:

Copy link

netlify bot commented May 13, 2024

Deploy Preview for ohif-platform-docs canceled.

Name Link
🔨 Latest commit 92a97bd
🔍 Latest deploy log https://app.netlify.com/sites/ohif-platform-docs/deploys/6642412b882ef900080299f7

Copy link

netlify bot commented May 13, 2024

Deploy Preview for ohif-dev ready!

Name Link
🔨 Latest commit 92a97bd
🔍 Latest deploy log https://app.netlify.com/sites/ohif-dev/deploys/6642412b17aaab000701d5ed
😎 Deploy Preview https://deploy-preview-4120--ohif-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@sedghi sedghi changed the title bind handleUnauthenticated to correct context fix(auth): bind handleUnauthenticated to correct context May 14, 2024
@sedghi sedghi merged commit 8fa339f into OHIF:master May 14, 2024
5 checks passed
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.

2 participants