Search code examples
javascriptfunctionstoreaccess-token

I want to store credential.access token in a variable, I tried the following but didn't succeed


var Token; 
componentDidMount() {
  auth0.webAuth.authorize({
    scope: 'openid profile email',
    audience: 'https://MyDomain/userinfo' 
   })
   .then(credentials => 
      console.log(credentials.accessToken))
      this.key=credentials.accessToken;
 }

Solution

  • Try this

    var Token; 
    componentDidMount() {
      auth0.webAuth.authorize({
        scope: 'openid profile email',
        audience: 'https://MyDomain/userinfo' 
       })
       .then(credentials => {
          console.log(credentials.accessToken);
          this.key=credentials.accessToken });
     }