You can do it by comparing the Discourse.User.current() expression with null.
Discourse.User.current()
null
See also:
How to show the «Log In» popup programmatically?