How to find out if user logged in

I need to insert a script into Admin > Customize > CSS/HTML. It has to run only if a user not logged in

I tried Discourse.User.current() but got a deprecation warning:

Deprecation notice: Import the User class instead of using User (deprecated since Discourse 2.4.0) (removal in Discourse 2.6.0)

Are there other ways to find it out?

<script type="text/discourse-plugin" version="0.8">
const user = api.getCurrentUser();
if(user) {
    // do stuff
}
</script>
3 Likes

Oh so I have access to api object there, that’s nice. Thanks!

<script>
    const user = api.getCurrentUser();
    console.log(user)
</script>

Uncaught ReferenceError: api is not defined

Oopsie

You need to specify the type of your script as:
<script type="text/discourse-plugin" version="0.8">

4 Likes

No mistakes, but nothing happens either. Anyway, thanks, at least now I know which way to dig

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