get regular user's token

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • talles.amadeu
    Junior Member
    • Jan 2020
    • 27

    get regular user's token

    this.getUser().get("token"); works for admin, but not for regular user. How can i get the user's token then?
  • item
    Active Community Member
    • Mar 2017
    • 1476

    #2
    Hi,
    not know if it's the best way, but this do the trick :
    so for admin and for regular user.

    PHP Code:
    
        getMyToken() {
                if (this.getUser().isAdmin()) {
                    return this.getUser().get('token');
                }else{
                    let cookies = document.cookie.split(";");
                    let cookie = [];
                    for(let i = 0; i < cookies.length; i++) {
                        cookie = cookies[i].split("=");
                        if('auth-token' == cookie[0].trim()) {
                            return decodeURIComponent(cookie[1]);
                        }
                    }
                }
                return null;
            },
    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

    Comment


    • talles.amadeu
      talles.amadeu commented
      Editing a comment
      Yeah, i got a similar workaround. But thanks a lot!
Working...