- Notifications
You must be signed in to change notification settings - Fork3
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
@@ -94,6 +96,9 @@ class AppState: ObservableObject { | |||
) | |||
if hasSession { | |||
_sessionToken = Published(initialValue: keychainGet(for: Keys.sessionToken)) | |||
if sessionToken == nil || sessionToken!.isEmpty == true { |
There was a problem hiding this comment.
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.
15066a3
to0617964
CompareUh oh!
There was an error while loading.Please reload this page.
// Sign out if token is expired | ||
Task { @MainActor in | ||
await state.handleTokenExpiry() | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
ethanndicksonMar 12, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
ethanndicksonMar 12, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
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.
dbd3eaf
tocc50b5d
Compare687f946
tobf95ba9
Comparebf95ba9
toc244963
Compareethanndickson commentedMar 18, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
9d93c0f
intomainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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.