Skip to content

Conversation

TheGostKasper
Copy link
Contributor

Closes
image

What changed?
Provide a redirect to signin form when unauthorized call is emitted

@TheGostKasper TheGostKasper added the bug Something isn't working label Oct 9, 2022
@ahussein3
Copy link
Contributor

There is already an Unauthorized interceptor that you can make use of here you can do that change here at the pipeline provider. As that change is duplicate of logic.

@ahussein3 ahussein3 self-requested a review October 10, 2022 10:36
@TheGostKasper
Copy link
Contributor Author

Using UnAuthorizedInterceptor which invoke a catch to every endpoint and check 401 to redirect to sign_in is valid but instead of wrapping services and change every provider then why not apply the same logic to one place which each endpoint use and save the wrapping as in our case will be :

  • Progressive delivery
  • pipelines
  • terraform

also in the future when we add more providers, we won't worry about this issue again and taking in consideration the alert and global error handler in one place if we want to do so !?
@ahussein3

@ahussein3
Copy link
Contributor

I Believe in having one interceptor all the components using it (Core, EE) is much better than having it two times.

@TheGostKasper
Copy link
Contributor Author

let's stick to EE then

@foot
Copy link
Collaborator

foot commented Oct 12, 2022

Yeah we want to avoid multiple ways of doing this if possible. Can we keep using the UnAuthorizedInterceptor everywhere or remove it everywhere (in core too)? If we go down this road then probably some util fn in core we can use in EE ?

import { maybeLogout } from "@weaveworks/weave-gitops";

...[snip]...
      onError: error => { maybeLogout(error); }

Agree having the logic in a single spot is nice. However should the handlers be on the QueryCache itself too? https://react-query-v3.tanstack.com/reference/QueryCache#global-callbacks

@TheGostKasper
Copy link
Contributor Author

In prev commit i used queryCache and noticed that for a sec Error displayed in UI Auth message before redirect to signin , I'm Ok to revert the last commit and keep it to queryCache .

Right, so we're keeping the error handler to useQuery and removing UnAuthorizedInterceptor everywhere else in EE (for this PR) ? then in a followup PR, export onError and remove UnAuthorizedInterceptor as well ?

@foot
Copy link
Collaborator

foot commented Oct 13, 2022

Right, so we're keeping the error handler to useQuery and removing UnAuthorizedInterceptor everywhere else in EE

Yes, does this approach work in core too? E.g. when working with the login handlers themselves or do they need to escape this somehow? Maybe they already use the UnAuthorizedInterceptor when calling signin so there is no real behaviour change.

I'm Ok to revert the last commit and keep it to queryCache .

My concern is that the queryCache handlers are always there, while doing it on the query-client only set defaults which we would be overriding in some places right now (e.g.

const { isLoading, data } = useQuery<ListTemplatesResponse, Error>(
'templates',
() => api.ListTemplates({}),
{
keepPreviousData: true,
onError,
},
);
), and in this case the auth-checking would be removed.

It would be nice to avoid a "flash of error message" before redirecting but maybe its unavoidable using this approach..

@TheGostKasper
Copy link
Contributor Author

TheGostKasper commented Oct 13, 2022

Yes, does this approach work in core too? E.g. when working with the login handlers themselves or do they need to escape this somehow?

Yes, core uses react-client as well

It would be nice to avoid a "flash of error message" before redirecting but maybe its unavoidable using this approach..

it's unavoidable yes

const { isLoading, data } = useQuery<ListTemplatesResponse, Error>( ...

In this case we might move the the notification to the shared onError or we keep the "flash of message" , any other Options !?

@foot

@TheGostKasper
Copy link
Contributor Author

@foot, what do you think 👆 ?

@TheGostKasper TheGostKasper requested a review from a team October 19, 2022 00:26
@enekofb enekofb self-requested a review October 19, 2022 14:46
@enekofb
Copy link
Contributor

enekofb commented Oct 19, 2022

tested that works by

  1. logged in, i could see resource

Screenshot 2022-10-19 at 16 46 49

2) deleted cookie token
  1. sent to login

Screenshot 2022-10-19 at 16 47 13

  1. after login, I am back to the last screen
    btw, is not pipelines but flux controllers cause the screenshot was taken in that flow but all good

Screenshot 2022-10-19 at 16 50 48

code: number;
message: string;
}
const queryClient = new QueryClient({
Copy link
Contributor

@enekofb enekofb Oct 19, 2022

Choose a reason for hiding this comment

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

do we need any unit tests for this behaviour?

Copy link
Contributor

@enekofb enekofb left a comment

Choose a reason for hiding this comment

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

Tested that works and the change make logical sense to me so approving based on that.

@TheGostKasper other concerns like interceptors or oss compatibility has not been considered ... in case you think they are a required before merge, other folks might need to check

my last suggestion would be to add some level of automated testing before merging

@TheGostKasper TheGostKasper merged commit 4da74c1 into main Oct 23, 2022
@TheGostKasper TheGostKasper deleted the fix-unhandeled-auth-redirect branch October 23, 2022 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants