Announcement

Collapse
No announcement yet.

get regular user's token

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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?

  • #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 0cookies.lengthi++) {
                        
    cookie cookies[i].split("=");
                        if(
    'auth-token' == cookie[0].trim()) {
                            return 
    decodeURIComponent(cookie[1]);
                        }
                    }
                }
                return 
    null;
            },
    ​ 

    Comment


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