Small issue with GitHub OAuth Task

Hi,

I am currently doing the OAuth Github task at the end of the User Authentication module. It works fine, however I have come across an issue.

In this last section where you write the function

function middleWare(req, res, next) {
  if(req.isAuthenticated()){ return next() };
  res.redirect('/redirect');
}

The isAuthenticated() function does not appear on the auto complete in visual studio. If I start to write req. it does not show up in the list of functions. I have tired opening the solution code just in case I did anything wrong and it doesn’t work there either.

The functionality works fine but it is just weird that it doesn’t show up and it makes me think there is something wrong with the code maybe.

Thanks

What package etc are you using for authentication? If it’s passport, req.isAuthenticated() is a perfectly valid function. VSCode’s autocomplete isn’t perfect all the time, so ultimately if your code works as intended I’d not worry about it :slight_smile:

1 Like

Yeah I am using passport. It’s strange why it doesn’t appear, I’ve never had this issue with VS code before

Ok, so something very strange. If I write this function:

function ensureAuthenticated (req, res, next){
  if(req.isAuthenticated()){  
    return next();
  } else{
    res.redirect('/')
  } 
}

The isAuthenticated() auto completes literally everywhere but in that if statement. It appears if I write it in that function but not in the if statement, it appears outside of that function and it also appears if I create an additional if statement in that same function. It just does not appear in the first if statement in that function and I can’t figure out why.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.