# How to find out if user logged in

**URL:** https://meta.discourse.org/t/how-to-find-out-if-user-logged-in/166099
**Category:** Support
**Created:** [October 3, 2020, 11:08am UTC](https://meta.discourse.org/t/how-to-find-out-if-user-logged-in/166099 "2020-10-03T11:08:12Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![MrDarkside](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mrdarkside/32/196020_2.png) [@MrDarkside](https://meta.discourse.org/u/MrDarkside)
#### Post date: [October 3, 2020, 11:08am UTC](https://meta.discourse.org/t/how-to-find-out-if-user-logged-in/166099/1 "2020-10-03T11:08:13Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [October 3, 2020, 11:32am UTC](https://meta.discourse.org/t/how-to-find-out-if-user-logged-in/166099/2 "2020-10-03T11:32:35Z")

</div>

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

```

---

<div class="post-metadata">

### Author: ![MrDarkside](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mrdarkside/32/196020_2.png) [@MrDarkside](https://meta.discourse.org/u/MrDarkside)
#### Post date: [October 3, 2020, 2:41pm UTC](https://meta.discourse.org/t/how-to-find-out-if-user-logged-in/166099/3 "2020-10-03T14:41:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![MrDarkside](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mrdarkside/32/196020_2.png) [@MrDarkside](https://meta.discourse.org/u/MrDarkside)
#### Post date: [October 3, 2020, 3:02pm UTC](https://meta.discourse.org/t/how-to-find-out-if-user-logged-in/166099/4 "2020-10-03T15:02:15Z")

</div>

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

```

> Uncaught ReferenceError: api is not defined

Oopsie

---

<div class="post-metadata">

### Author: ![loginerror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/loginerror/32/156605_2.png) [@loginerror](https://meta.discourse.org/u/loginerror)
#### Post date: [October 3, 2020, 3:11pm UTC](https://meta.discourse.org/t/how-to-find-out-if-user-logged-in/166099/5 "2020-10-03T15:11:44Z")

</div>

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

---

<div class="post-metadata">

### Author: ![MrDarkside](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mrdarkside/32/196020_2.png) [@MrDarkside](https://meta.discourse.org/u/MrDarkside)
#### Post date: [October 3, 2020, 3:45pm UTC](https://meta.discourse.org/t/how-to-find-out-if-user-logged-in/166099/6 "2020-10-03T15:45:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [November 2, 2020, 3:56pm UTC](https://meta.discourse.org/t/how-to-find-out-if-user-logged-in/166099/7 "2020-11-02T15:56:56Z")

</div>

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