# Widget's user awareness

**URL:** https://meta.discourse.org/t/widgets-user-awareness/146275
**Category:** Development
**Created:** [March 31, 2020, 2:02pm UTC](https://meta.discourse.org/t/widgets-user-awareness/146275 "2020-03-31T14:02:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Fausto\_Dassenno](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fausto_dassenno/32/166480_2.png) [@Fausto\_Dassenno](https://meta.discourse.org/u/Fausto_Dassenno)
#### Post date: [March 31, 2020, 2:02pm UTC](https://meta.discourse.org/t/widgets-user-awareness/146275/1 "2020-03-31T14:02:52Z")

</div>

What is the best way to get the user object inside a widget?

```
api.createWidget("login-button", {
  tagName: "button.btn.btn-primary",

  html(arg) {
     {{IF USER IS LOGGED IN}}
     return username;
  },

  click(arg) {}

```

);

---

<div class="post-metadata">

### Author: ![zcuric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zcuric/32/292837_2.png) [@zcuric](https://meta.discourse.org/u/zcuric)
#### Post date: [March 31, 2020, 4:35pm UTC](https://meta.discourse.org/t/widgets-user-awareness/146275/2 "2020-03-31T16:35:21Z")

</div>

You can use:

```plaintext
const user = api.getCurrentUser()

if(user) {
  return user.username;
}

```

More info here:

> [@Developing Discourse Themes & Theme Components](https://meta.discourse.org/t/developer-s-guide-to-discourse-themes/93648#heading--4-c-2):
>
> Discourse Themes and Theme Components can be used to customize the look, feel and functionality of Discourse’s frontend. This section of the developer guides aims to provide all the reference materials you need to develop simple themes for a single site, right up to complex open-source theme components. This introduction aims to provide a map of all the tools and APIs for theme development. If you prefer a step-by-step tutorial for theme development, jump straight to: Themes vs. Theme Compon…
