Negating the result of a promise in a guard

return !this.authService.isLoggedIn() won't work, because of how JS works. this.authService.isLoggedIn() is promise object and is truthy. !this.authService.isLoggedIn() will always be false.

Instead, promise result should be mapped to negated result with

canActivate() {
    return this.authService.isLoggedIn().then(result => !result);
}

Or

async canActivate() {
    return !(await this.authService.isLoggedIn());
}

The parentheses around await ... are optional and used for readability.


All you need to do is some further manipulation of the promise's resolved value:

canActivate() {
    return this.authService.isLoggedIn().then(loggedIn => !loggedIn);
}

And if you're inside an if statement and async/await is enabled move the negation inside the parenthesis.

if (!await client.bucketExists('test')) {}