# How to get the current\_user details in Discourse.Dialect.postProcessText for both client and server side?

**URL:** <https://meta.discourse.org/t/how-to-get-the-current-user-details-in-discourse-dialect-postprocesstext-for-both-client-and-server-side/48391>\
**Category:** Development\
**Created:** [2016 年8 月 9 日 11:07 UTC](https://meta.discourse.org/t/how-to-get-the-current-user-details-in-discourse-dialect-postprocesstext-for-both-client-and-server-side/48391 "2016-08-09T11:07:34Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

作者： ![krishnau2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/krishnau2/32/121598_2.png) [@krishnau2](https://meta.discourse.org/u/krishnau2)\
发布日期： [2016 年8 月 9 日 11:07 UTC](https://meta.discourse.org/t/how-to-get-the-current-user-details-in-discourse-dialect-postprocesstext-for-both-client-and-server-side/48391/1 "2016-08-09T11:07:34Z")

</div>

Hi,

In my discourse app, I want to mask sensitive content inside posts (email/phone numbers etc.)

I wrote a plugin by following ALL CAPS plugin by @sam.

This is what I came up with

```
function mask_sensitive_content (text){
  var emailRegex = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/ig;
  var mobileRegex = /\b\+?\d[\d]{8,12}\d/g;
  
  var emailReplaceWith = ' ---@---.--- ';
  var mobileReplaceWith = ' ########## ';

  return text.replace(mobileRegex, mobileReplaceWith)
    .replace(emailRegex, emailReplaceWith);
}

Discourse.Dialect.postProcessText(function (text) {
  return mask_sensitive_content(text);
});

```

This masking works both on the client-side and server-side (the data is being written into db after masking).

But I now need to exclude admins and moderators from masking. I looked through several plugins and discussions in meta.discourse and made this:

```
Discourse.Dialect.postProcessText(function (text) {

  var current_user = null
  if(Discourse.User && Discourse.User.current()){
    current_user = Discourse.User.current();
  }

  // Not masking the content if its an admin or moderator
  if(current_user != null && (current_user.admin == false || current_user.moderato == false)){
    return mask_sensitive_content(text);
  }
});

```

This works perfectly in the editor, but when I save the content, it is not getting masked. Seems like my code doesn’t have any effect.

On further investigation I found Discourse.User.current() is causing a problem in the backend while trying to cook the content, since Discourse.User is not available there.

Do you have any hints on how I should go about this?

---

_[View the full topic](https://meta.discourse.org/t/how-to-get-the-current-user-details-in-discourse-dialect-postprocesstext-for-both-client-and-server-side/48391)._
