Skip to content

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

Description

@mdimec4

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: http://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>

Activity

  1. bitnom commented on Mar 11, 2024

    @bitnom

    Possible duplicate of #1271

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions