Web: Redirect to login upon missing session cookie#33726
Merged
Conversation
gzdunek
approved these changes
Oct 20, 2023
Contributor
gzdunek
left a comment
There was a problem hiding this comment.
LGTM, I left a few minor comments.
| </DialogHeader> | ||
| <DialogContent> | ||
| <Alert kind="danger" children={errMsg} /> | ||
| <Text mb={3}>Try again by refreshing the browser.</Text> |
Contributor
There was a problem hiding this comment.
Suggested change
| <Text mb={3}>Try again by refreshing the browser.</Text> | |
| <Text mb={3}>Try again by refreshing the page.</Text> |
|
|
||
| import history from 'teleport/services/history'; | ||
|
|
||
| export function ErrorDialogue({ errMsg }: { errMsg: string }) { |
| const { attempt, setAttempt } = useAttempt('processing'); | ||
|
|
||
| useEffect(() => { | ||
| const checkUserIsAuthenticated = async () => { |
Contributor
There was a problem hiding this comment.
Suggested change
| const checkUserIsAuthenticated = async () => { | |
| const checkIfUserIsAuthenticated = async () => { |
Comment on lines
+52
to
+57
| if (!session.isValid()) { | ||
| logger.warn('invalid session'); | ||
| session.clear(); | ||
| history.goToLogin(true); | ||
| return; | ||
| } |
| } | ||
|
|
||
| return <>{children}</>; | ||
| return null; |
Contributor
There was a problem hiding this comment.
WDYT of showing an <Indicator /> during loading?
Comment on lines
+208
to
+209
| * which just checks if the cookie sent from browser is valid and user | ||
| * session is still valid. |
Contributor
There was a problem hiding this comment.
I'd shorten it a bit:
Suggested change
| * which just checks if the cookie sent from browser is valid and user | |
| * session is still valid. | |
| * which checks if the cookie and the user session are still valid. |
ryanclark
approved these changes
Oct 20, 2023
6233ed8 to
84c5cee
Compare
This was referenced Oct 23, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #20996
Why: We use non-persistent (session) cookie. When you close a browser, session cookies get cleared from the browser. Then when you re-open browser, load the teleport app, try to make a teleport api call to a protected endpoint WithAuth, it fails to authn because a cookie wasn't sent with the request.
There is three kind of dialogue shown depending on which webapp route you take.
AppLauncher component catches error (from trying to
getFqdn)Reproduce (chrome, but works on any browser):
Enterprise: the WaitingRoom catches error (from trying to
getUserContext)Open source: the root CatchError catches error (from trying to
getUserPreferences)Our component tree looks like this:
Prior to this PR, in the
Authenticatedlayer we were only checking for valid session stored in local storage. But gives false positives. Now we just make the api call to the/statusendpoint right away and fail earlier in the tree (instead of 15 seconds later from starting an interval timer that polls this endpoint)All the above scenarios, the user will be redirected to the login right away. On rare occassions where the
/statusjust fails to fetch, this is what the user will see: