Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
Variable cannot access outside .then()

I am trying to set a authenticator for my local application. Found that I am not able to access my var outside my .then() method

var authenticated = false;
Auth.findtheUser({
}).then(user => {
  verified= user.name.verified;
  console.log("authenticated11", verified)
}
).catch(err => console.log(err));
console.log("authenticated", verified)

the output for authenticated11 output comes as true but not the one at the end Could anyone help me out on this. New to javascript.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You cant use the result of an asynchronous function directly after it in JS. See this question: How to return the response from an asynchronous call

about 4 years ago · Juan Pablo Isaza Report

0

According to what you described in a comment in this answer. You are facing an exception related to the scope.

var authenticated = false;
Auth.findtheUser({
  }).then(user => {
    verified= user.name.verified;
    console.log("authenticated11", verified)
}
).catch(err => console.log(err));
// This will throw an exception because verified does not exist in this scope
console.log("authenticated", verified)

You should change that to this

var authenticated = false;
var verified;
Auth.findtheUser({
  }).then(user => {
    verified= user.name.verified;
    console.log("authenticated11", verified)
}
).catch(err => console.log(err));
// This will throw an exception because verified does not exist in this scope
console.log("authenticated", verified)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!