Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: sign user out if token is expired#109

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethanndickson merged 1 commit intomainfromethan/sign-out-on-expiry
Mar 18, 2025

Conversation

ethanndickson
Copy link
Member

@ethanndicksonethanndickson commentedMar 11, 2025
edited
Loading

Closes#107.

When the menu bar icon is clicked, and the user is signed in, and the VPN is disabled, the app will check if the token is expired. If it is, the user will be signed out.

We could have checked this when the VPN is enabled, but the UX seemed worse, and the implementation would have been messy. We would have needed to sign the user out and show an error. Instead, we'll check for expiry in a scenario where the next user step would likely be an interaction that requires a session.
This approach also future-proofs for when functionality becomes usable without the VPN.

matifali reacted with rocket emoji
@ethanndicksonGraphite App
Copy link
MemberAuthor

This stack of pull requests is managed byGraphite. Learn more aboutstacking.

@ethanndicksonethanndickson changed the titlechore: sign user out on launch if token expiredchore: sign user out on launch if token is expiredMar 11, 2025
@ethanndicksonethanndickson marked this pull request as ready for reviewMarch 11, 2025 07:08
@@ -94,6 +96,9 @@ class AppState: ObservableObject {
)
if hasSession {
_sessionToken = Published(initialValue: keychainGet(for: Keys.sessionToken))
if sessionToken == nil || sessionToken!.isEmpty == true {
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can end up in this state if the user deleted it from the keychain themselves.

ThomasK33 reacted with thumbs up emoji
Comment on lines 59 to 75
// Sign out if token is expired
Task { @MainActor in
await state.handleTokenExpiry()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Will this run initially or periodically?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Just once on launch. The token gets refreshed on use, so if the user toggles the VPN another week (by default) gets added to the expiry date. That means we're not covering the case where the user keeps the app open for a while without using it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Got it. Is this a case we should consider or is it unlikely for GA?

Copy link
MemberAuthor

@ethanndicksonethanndicksonMar 12, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'd definitely like to be able to handle that case but, I don't think running it on a fixed interval is the right solution.
I realised it would be ideal if we could check the expiry if:

  • The user is signed in
  • The VPN is off
  • The menu bar icon is clicked

If the VPN is on, then the token has almost certainly been refreshed recently.
So, I did this with a quick commit to ourFluidMenuBarExtra fork.
I think having theseonAppear andonDisappear handlers is useful, in general, in case we ever want to refresh some state when the menu is opened.
For reference, the existingView.onAppear only runs when the view first appears for our menu bar window, as the view technically always exists, it's just not visible.

From pr desc:

We could have checked this when the VPN is enabled, but the UX seemed worse, and the implementation would have been messy. We would have needed to sign the user out and show an error.
This approach also future-proofs for when functionality becomes usable without the VPN

ThomasK33 reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Got it, thanks. I was thinking of the Tailscale experience, which shows me how long the device keys remain valid and when my login expires.

Can we potentially fetch information on when the token should expire (in the regular scenario) and display it in the UI? For example, if the token will expire in 24 hours, we conditionally show a red text that says "token expiring soon, please log in soon again" (or something comparable), but otherwise, it won't be shown.

Copy link
MemberAuthor

@ethanndicksonethanndicksonMar 12, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm not sure a warning is useful, the session tokens have a pretty long default duration (7 days, and we only made it configurable late last year) and they refresh on use. If someone sees the warning by opening the menu, they were probably going to use the app anyway, which would refresh it.

As an aside, there's unfortunately no way to listcli-auth tokens, as there's no way to view information of tokens of typeloginTypePassword via our API. Manually created tokens (coder tokens create) are of typeloginTypetoken, which is all we support listing.

I think even if we did add a way to fetch those session durations, we have a HTTP middleware that refreshes on every request that requires a token, making the duration immediately either outdated or equal to the post-refresh duration.

@ethanndicksonethanndickson changed the titlechore: sign user out on launch if token is expiredchore: sign user out if token is expiredMar 12, 2025
@ethanndicksonethanndickson self-assigned thisMar 12, 2025
@ethanndicksonethanndicksonforce-pushed theethan/sign-out-on-expiry branch 2 times, most recently from687f946 tobf95ba9CompareMarch 12, 2025 05:50
@ethanndicksonGraphite App
Copy link
MemberAuthor

ethanndickson commentedMar 18, 2025
edited
Loading

Merge activity

  • Mar 17, 11:36 PM EDT: A user started a stack merge that includes this pull request viaGraphite.
  • Mar 17, 11:36 PM EDT: A user merged this pull request withGraphite.

@ethanndicksonethanndickson merged commit9d93c0f intomainMar 18, 2025
4 checks passed
@ethanndicksonethanndickson deleted the ethan/sign-out-on-expiry branchMarch 18, 2025 03:36
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ThomasK33ThomasK33ThomasK33 approved these changes

Assignees

@ethanndicksonethanndickson

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Opening the app with an expired token should sign the user out
2 participants
@ethanndickson@ThomasK33

[8]ページ先頭

©2009-2025 Movatter.jp