Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggestion: Handle session expiration gracefully #526

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

cmaddox5
Copy link
Contributor

Even after #520, we still need to handle errors when someone has Screenplay open during a deploy. I think this can best be handled by looking for api in the previous path and returning a 403 instead of a redirect. This allows us to throw/catch an exception on the client and display a modal letting the user know they need to refresh the page.

Screenshot 2024-10-15 at 1 51 35 PM

@cmaddox5 cmaddox5 requested a review from a team as a code owner October 15, 2024 17:52
@@ -9,8 +9,12 @@ defmodule ScreenplayWeb.AuthManager.ErrorHandler do

@impl Guardian.Plug.ErrorHandler
def auth_error(conn, error, _opts) do
auth_params = auth_params_for_error(error)
Phoenix.Controller.redirect(conn, to: ~p"/auth/keycloak?#{auth_params}")
if Plug.Conn.get_session(conn, :previous_path) =~ "api" do
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we be looking at the current request path rather than the previous one? I'm surprised we set a "previous path" for API requests at all — I'd expect that value to always be some browser-navigable route.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the main reason for holding onto the previous path is for the sake of auth redirects. When you log in to Keycloak, you're temporarily not at the URL you want to be at so we help the user get there by holding on to their original request path. I used it here just in case it landed in this function from a Keycloak request. Because save_previous_path/2 is part of the request pipeline, it would be the same URL regardless of where the error surfaced.

.catch((response: Response) => {
if (response.status === 403) {
setIsAlertsIntervalRunning(false);
setShowModal(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems we'd only show this modal if, specifically, a background alerts request fails. How is the experience if some other kind of "foreground" request fails? Should we try to integrate this into all instances where we fetch data from the server?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because this task was already kind of scope creep-y, I focused specifically on what I knew to be the problem we see in Sentry.

You do raise a good point though. We've had a habit of assuming a request will be successful so we unintentionally fail silently in some areas. For example, I hardcoded a 500 for the Associate with alert page and the only indicator that something went wrong is that the table is empty. Because this would be a bigger task, I'll get it added to the backlog for us to talk about in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants