diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js
index a1d55dcf0eb6180f08df452b4e60c429fdce15dd..db7d65527dac966338fda587d2866b513c431eda 100644
--- a/javascript/src/iframe/viamapi-iframe.js
+++ b/javascript/src/iframe/viamapi-iframe.js
@@ -1277,7 +1277,7 @@ connection.promise.then(parent => {
       if (!pinCode) {
         if (!identityLoadedEvent) {
           const result = await loadIdentityInternal(window.currentlyLoadedIdentity.authentication.publicKey, "00000000");
-          if (result.code !== "200") {
+          if (window.currentlyLoadedIdentity && result.code !== "200") {
             const event = createEvent("CanNotLoadPincodeForLoadedIdentity", "IdentityNotLoaded", [window.currentlyLoadedIdentity.authentication.publicKey]);
             parent.onEvent(event);
             identityLoadedEvent = true;