Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mdimec4 opened this issue Dec 26, 2023 · 1 comment

Comments

@mdimec4
Copy link

mdimec4 commented Dec 26, 2023

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>
@bitnom
Copy link

bitnom commented Mar 11, 2024

Possible duplicate of #1271

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants