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

Context issue in userProfile(token, done)() #24

Open
bgbahoue opened this issue Aug 13, 2015 · 0 comments
Open

Context issue in userProfile(token, done)() #24

bgbahoue opened this issue Aug 13, 2015 · 0 comments

Comments

@bgbahoue
Copy link

I created a class that inherits from one of the predefined Passport strategy (OAuth2 from passport-oauth) to be able to add some specific code. I ran into an issue with the context (this) that is set in the userProfile() method (call by the internal passport logic to create the user's profile)

Is there a workaround to be able to get / pass-on a reference of my GenericOAuth2Strategy ?

Thanks in advance

--- My code (simplified) ---

function GenericOAuth2Strategy(name, options, verify) {
    // do something
    this._name = "my name";
    OAuth2Strategy.call(this, options, verify);
}

require('util').inherits(GenericOAuth2Strategy, OAuth2Strategy);

GenericOAuth2Strategy.prototype.myFunction() {
    // In here this is not equal to my current GenericOAuth2Strategy
    console.log(this);
    console.log(this._name); // => this throw an error see below
    console.log(this.getName()); // => this throw an error see below
}

GenericOAuth2Strategy.prototype.userProfile = function(accessToken, done) {
    this.myVar = 'toto';
    this.myFunction(); // this is called
}

--- Console output ---

This = { success: [Function],
  fail: [Function],
  redirect: [Function],
  pass: [Function],
  error: [Function],
  myVar: 'toto' }

When I try to access 'this._name' I get this error

This._name = undefined

When I try to access 'this.getName()' I get this error

GenericOAuth2Strategy.js:xx
console.log("This._name = %s", this.getName());

TypeError: undefined is not a function
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

No branches or pull requests

1 participant