Repository navigation
fix: restore previous session on coder server --dev - #1821
Conversation
|
|
||
| oldURL, err := cfg.URL().Read() | ||
| if err != nil { | ||
| return nil, xerrors.Errorf("write local url: %w", err) |
There was a problem hiding this comment.
This would fail if an old session didn't exist, right?
mafredri
left a comment
There was a problem hiding this comment.
Thanks for taking a look at this issue! I think Kyle's comment warrants a small change but other than that, LGTM!
| } | ||
| } | ||
| err = createFirstUser(cmd, client, config, devUserEmail, devUserPassword) | ||
| cleanupSession, err := createFirstUser(logger, cmd, client, config, devUserEmail, devUserPassword) |
There was a problem hiding this comment.
Suggestion: Would restore/restorePreviousSession be more descriptive here?
| if err != nil { | ||
| logger.Error(cmd.Context(), "failed to read current session token", slog.Error(err)) | ||
| return | ||
| } |
There was a problem hiding this comment.
Thought: Do we need to consider cases where the user has tried the logout flow or ran coder login against the dev server? If so we could consider renaming the files to {url,session}.bak, and if those files are present on exit, (or startup), restore them. Perhaps even dev tokens could be a different format from non-dev, that way we could always identify if a restore case is appropriate or not.
Being able to restore on startup would also cover cases where the server is killed instead of graciously exited.
I'm probably overthinking this though, this change alone should help alleviate the most common cases.
There was a problem hiding this comment.
I think as a first pass I'd rather not try to guess, because I could see devs spending quite a while trying to figure out what's wrong before they realize it's the session. Currently if it's different that we would expect we just choose "do nothing", and I'm down to add more logic here as we use it and run into cases.
Fixes #1747