Autologin

Version: v2.0

Autologin allows the customer to automatically be logged in to a webshop. Autologin is only available if the customer already has an account, has autorized WebshopLogin to share personal information with that webshop and has given the webshop permission to use autologin in their ShopLogin account.


Autologin should only be performed when webshoplogin.user.autologin and webshoplogin.user.loggedIn is true in the Javascript. If both variables are true you should add an eventlistener to “getAccesstokenResponse” which calls a autologin function. From there you can send a request to the backend of the webshop to login the user.

<script>
    if(webshoplogin.user.autologin && webshoplogin.user.loggedIn){
        document.addEventListener("getAccesstokenResponse", autologin);
        webshoplogin.accesstoken();
    };
    function autologin(event){
         var xhttp = new XMLHttpRequest();
         xhttp.open('GET', "yoururl?accesstoken=" + event.detail.accesstoken);
         xhttp.send();
    }
</script>

Replace "yoururl" in the example code with the URL pointing to the autologin endpoint of your plugin. Use the accesstoken to retrieve the userdata and perform a login in the backend of your webshop.