JavaScript wait for asynchronous function in if statement [duplicate]

I do this exact thing using async/await in my games code here

Assuming req.isLoggedIn() returns a boolean, it’s as simple as:

const isLoggedIn = await req.isLoggedIn();
if (isLoggedIn) {
    // do login stuff
}

Or shorthand it to:

if (await req.isLoggedIn()) {
    // do stuff
} 

Make sure you have that inside an async function though!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)