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

Auth Attempt Failed: Public Key Does Not Exist #574

Closed
509dave16 opened this issue Jul 11, 2018 · 6 comments
Closed

Auth Attempt Failed: Public Key Does Not Exist #574

509dave16 opened this issue Jul 11, 2018 · 6 comments

Comments

@509dave16
Copy link

509dave16 commented Jul 11, 2018

TLDR

@amark I think the issue stems from the gunRoot not being populated with 'public key': 'user' pairs. query.js looks for those. After create.js puts one on the root, I can see it on my server peer and my browser peer. But for some reason on refresh, the direct children of the root for public keys are not there anymore on the browser peer.

Expected behavior

When executing gun.user().auth(<username>,<password>, cb), I expect that a previously created user should be logged in.

Resulting behavior

auth_attempt_failed_public_key_does_not_exist

Troubleshooting Information

Hypothesis

  • gunRoot.get(pub).get((at, ev) => {(offender) is trying to access a path where there is no put value.
  • Somehow between refreshes after a creating a user the nodes that should be there for public keys are gone
@509dave16
Copy link
Author

@amark Found a work around. The way that recall is handled is interesting but there's problems with gun.user().recall({ sessionStorage: true}); in how the promise settles and the fact that a callback is not passed to the gun.user().auth(...). So I pass the recall option and re-implement what recall does for auth.

// Instantiating Gun
const gun = Gun({
	peers: ['http://localhost:8082/gun'],
	recall: true
});
...
// Elsewhere in whatever is used to check for authentication
public async isAuthenticated(): Promise<any> {
	const tmp = window.sessionStorage;
		if (tmp) {
			if (tmp.alias && tmp.tmp) {
			try {
			        await this.login({ username: tmp.alias, password: tmp.tmp});
				return true;
			} catch (e) {
				console.log(e);
			}
		}
	}
	return false;
}

I'm hoping to contribute to helping address whatever issues currently exist with SEA for auth. Let me know if what above doesn't make sense.

@509dave16
Copy link
Author

509dave16 commented Jul 11, 2018

@amark I thought my work around above worked, but it actually doesn't :( . When trying to access User nodes, nothing was happening. Below are screenshots of the same attempt to .get a profile node from the User like this gun.user().get('profile');

Right after logging in

screen shot 2018-07-11 at 3 22 54 pm

Right after refresh

screen shot 2018-07-11 at 3 21 23 pm

Turns out those sessionStorage items are only temporary and they are gone on refresh.

@509dave16
Copy link
Author

509dave16 commented Jul 12, 2018

@amark Closing this for now. It got muddied with different issues I ran into. Here's the gist of what I have done to make this work by doing my own storage management.
https://gist.github.com/509dave16/ee952c687424822dbc667cae1d71cff7

@amark
Copy link
Owner

amark commented Jul 12, 2018

@509dave16 excellently reported, thank you for the thoroughness, it is super appreciated/helpful.

And also super thanks for dealing with workarounds for now.

sessionStorage should persist upon refresh (but not exit, and come back later).

It seems to me that maybe it isn't .recall that is failing, but my comment in #579 ?

@jadbox
Copy link
Contributor

jadbox commented Jul 13, 2018

@509dave16 did you find out how you solved the "Public key is missing" error? I can't seem to get past it.

@509dave16
Copy link
Author

509dave16 commented Jul 15, 2018

@jadbox I avoided using recall. So stored the credentials in the session myself. And then would re-authenticate on every page if the user wasn't already logged in. But this just introduced a new problem where the re-authentication on refresh introduced a new owner every time. So any data created the first time the creds were authenticated would be fine. Until I did a refresh and the re-auth kicked in again, introducing a new owner that didn't have access.

My personal recommendation would be to avoid using SEA for now. And just use straight up gun. If you alias it like 'const gunUser = gun;then later when SEA works properly you could just switch it toconst gunUser = gun.user()`.

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

3 participants