Get the logged in user

To get the currently logged in user, first have weasl installed on your website, then use:

var userPromise = weasl.getCurrentUser();

This will return a promise that will resolve to the current user. To see that data, do something like this:

weasl.getCurrentUser().then(console.log);

and you will see data that looks like this in the console:

{
    "activity": {
        "created_at": "Mon, 20 Aug 2018 01:45:08 GMT",
        "last_login_at": "Mon, 20 Aug 2018 01:45:08 GMT",
        "updated_at": "Mon, 20 Aug 2018 01:45:08 GMT"
    },
    "attributes": {
        "name": {
            "value": "Ryan",
            "trusted": false,
        }
    },
    "id": "26b769e6-b27a-4d68-ce27-1b4386912d5e",
    "identity": {
        "email": null,
        "phone_number": "5555555555"
    }
}

If the user is not logged in, you will get the value "undefined" back as the current user.


Did this help answer your question?

thumbs up
thumbs down

Thanks for the feedback! 🙏🏽


Help by drift