dissent icon indicating copy to clipboard operation
dissent copied to clipboard

Remembering login session when logging in with username/password?

Open nyanpasu64 opened this issue 3 years ago • 10 comments

Currently gtkcord4 does not remember your username/password or the resulting token. Looking at https://github.com/diamondburned/gtkcord4/blob/main/internal/gtkcord/window/login/component.go, only loginToken() calls SecretDriver().Set(), and loginEmail() does not.

Can the code be changed to remember to remember the generated token (and possibly username/password though not 2FA code, in case the token expires)?

(Is this something straightforward enough for me to contribute a PR, or is it architecturally complex enough for you to do it yourself?)

nyanpasu64 avatar Jul 03 '22 00:07 nyanpasu64

Currently gtkcord4 does not remember your username/password or the resulting token.

It does. After the username and password are given, the returned token is stored. That's why there's a Remember Me checkbox for both Username/Password and Token logins.

diamondburned avatar Jul 03 '22 01:07 diamondburned

the returned token is stored

I tried logging in in gtkcord4. After opening Seahorse (Passwords and Keys), it showed the only password saved by gtkcord4 is __secret_available_000 from Keyring::IsAvailable(). No token is saved. (Incidentally when I try running gtkcord4 in a terminal, I see a message note: account not found from driver: key not found. I think all this means is that no saved token was found.)

Why is that? Only login() → loginToken() calls:

driver := c.Remember.SecretDriver()
...
driver.Set("account", []byte(token))
...
c.page.asyncUseToken(token)

Whereas login() → loginEmail() calls gtkutil.Async() (not sure exactly what that does, but I'd have to figure out to make a PR) running:

u, err := session.Login(c.ctx, email, password, totp)
...
return func() {
	c.page.asyncUseToken(u.Token)

with no call to driver.Set("account", []byte(u.Token));, nor a call to loginToken().

Unless my observations and code reading are mistaken, the "Remember Me" checkbox is a no-op in Username/Password mode. Did I make an error somewhere in my reading?

nyanpasu64 avatar Jul 03 '22 02:07 nyanpasu64

I think you're right. Perhaps component.go:186 should be calling c.loginToken.

Can you test that and see if it works?

diamondburned avatar Jul 03 '22 06:07 diamondburned

How would I test the change locally?

Editing ~/go/... failed to save the file. I tried cloning gtkcord4 and editing that, then ran go install -v ., and now it's busy burning 1 of 2 of my old CPU cores on gcc (it would be a lot more wasteful on my modern 12-thread CPU where I run Electron Discord rather than gtkcord4 on), and it looks like parallelization is an open issue. (EDIT: After the build finished, email login saves the password properly.)

Apparently it's building github.com/diamondburned/gotk4/pkg/gdk/v4 and friends a second time, after I've already waited half an hour yesterday on go install -v github.com/diamondburned/gtkcord4@latest, which already built the same packages. Why is it doing this?

(In theory, if the bug lied in a dependency, what would be the best way to patch it locally? Manually downloading the dependency, then adding a "replace" statement in go.mod (not much better than Cargo)?)

nyanpasu64 avatar Jul 03 '22 18:07 nyanpasu64

and now it's busy burning 1 of 2 of my old CPU cores on gcc (it would be a lot more wasteful on my modern 12-thread CPU where I run Electron Discord rather than gtkcord4 on),

You can use the patched Go compiler. See gotk4-nix.

Apparently it's building github.com/diamondburned/gotk4/pkg/gdk/v4 and friends a second time, after I've already waited half an hour yesterday on go install -v github.com/diamondburned/gtkcord4@latest, which already built the same packages. Why is it doing this?

@latest fetches v0.0.3. git cloneing fetches the head commit.

(In theory, if the bug lied in a dependency, what would be the best way to patch it locally? Manually downloading the dependency, then adding a "replace" statement in go.mod (not much better than Cargo)?)

Yes.

diamondburned avatar Jul 03 '22 21:07 diamondburned

I have this issue too.

TriVoxel avatar Jul 10 '22 02:07 TriVoxel

I am also having the same issue

TheKrafter avatar Aug 08 '22 01:08 TheKrafter

Samsies! #metoo

4cecoder avatar Nov 05 '22 22:11 4cecoder

Potentially fixed in c6c0aab.

diamondburned avatar Nov 06 '22 22:11 diamondburned

#141 Might be a duplicate of this issue

tgm-git avatar Sep 08 '23 10:09 tgm-git