# Set current User in Javascript

**URL:** <https://meta.discourse.org/t/set-current-user-in-javascript/70263>\
**Category:** Development\
**Created:** [September 18, 2017, 10:55am UTC](https://meta.discourse.org/t/set-current-user-in-javascript/70263 "2017-09-18T10:55:46Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)\
**Post date:** [September 18, 2017, 11:18am UTC](https://meta.discourse.org/t/set-current-user-in-javascript/70263/4 "2017-09-18T11:18:55Z")

</div>

Your code is most likely running too early, before Discourse is initialized.  
How to fix this (or whether it needs a fix at all) depends on what you’re trying to do. In which context will the JavaScript code needing the username actually run?

---

_[View the full topic](https://meta.discourse.org/t/set-current-user-in-javascript/70263)._
