gun icon indicating copy to clipboard operation
gun copied to clipboard

Once dosen't trigger most of the time, when messages are authenticated to an user.

Open mdimec4 opened this issue 1 year ago • 1 comments

Expected behavior

See code snippet at the bottom. When message is authenticated to an user and stored, it is expected that once is consistently triggered with a messages that are also authenticated to an user.

Observed behavior

Most of the time nothing happens. Once is not triggered. Then sometimes in a very small number of cases, if I clear browser storage and retry once would trigger successfully with a full message or sometimes with an empty message.

<!DOCTYPE html>
<html>

<head>
</head>
<body>
    <script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/gun/sea.js"></script>
    <script>
        // based on: https://github.com/fireship-io/gun-chat
        const gun = GUN();
        const user = gun.user().recall({sessionStorage: true})
        
        const pageId = "page-url-hash-1314321";
        
        var username = "edi";
        var password = "pass12345678";
        
        if(!user.is) {
        	//signup(username, password);
        	login(username, password);
        }
        
        gun.on('auth', function(ack) {
    	console.log("AUTH " + ack);

        gun.get(pageId).get('comments').map().once(function(messageData) {
        	console.log(messageData);
                gun.user(messageData).get('alias').then(function(who) {
	            var when = GUN.state.is(messageData, 'what');
		    var comment = {user: who, time: when, message: messageData.what};
                    console.log(comment);               
		});
            });

	var messageData = user.get('all').set({ what: "comment content1"});
	gun.get(pageId).get("comments").set(messageData);
	
	var messageData2 = user.get('all').set({ what: "comment content2"});
	gun.get(pageId).get("comments").set(messageData2);
    })
        
        
        function login(username, password) {
            user.auth(username, password, ({ err }) => err && alert(err));
        }

        function signup(username, password) {
            user.create(username, password, ({ err }) => {
                if (err) {
                    alert(err);
                } else {
                   login(user, username, password);
               }
            });
        }
    </script>
</body>

</html>

mdimec4 avatar Dec 26 '23 06:12 mdimec4

Possible duplicate of https://github.com/amark/gun/issues/1271

bitnom avatar Mar 11 '24 23:03 bitnom