Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. COPassport supports asynchronous operation, that's why it passes the `done` callback function which you're supposed to call once your (async) user check is finished. There *is* a potential race condition with opening the database at app startup, but you can always wait for the database to connect before starting to accept incoming requests to your Express application.
      singulars
    2. COThe problem was that the callbacks weren't finishing in time--so I open the db connection early to remove one of the callbacks that must finish. But what if `findOne` takes longer than normal? I think I could end up in the same situation as before. In the code above, `done` is called in the last callback (as you suggest), but after much testing I have seen that passport does not wait for this. As soon as `mc.connect` finishes, passport moves on. It does finish, which is why the second request (when I refresh the page) gets authenticated. I've added an additional example to the question
      singulars
    3. COI think you're missing the finer nuances of asynchronous execution: when an async function is called, execution of the code following that call will continue. Passport won't (or rather: *can't*) wait for an async function to finish before continuing, therefore it passes a callback which will be called when the async function is done. In your example: you can't expect #8 to be logged last, because any of the async functions can finish later.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload