-
Notifications
You must be signed in to change notification settings - Fork 87
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
fix(form-v2): remove additional log in step when switching from AngularJS to React #4459
fix(form-v2): remove additional log in step when switching from AngularJS to React #4459
Conversation
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.
Lgtm
@@ -35,7 +41,15 @@ export const useAuth = (): AuthContextProps => { | |||
|
|||
// Provider hook that creates auth object and handles state | |||
const useProvideAuth = () => { | |||
const [isAuthenticated] = useLocalStorage<boolean>(LOGGED_IN_KEY) | |||
// TODO #4279: Remove after React rollout is complete | |||
const { data: user } = useQuery<UserDto>( |
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.
Comment: could we use the useUser hook directly? Or does the use user hook look at the localStorage value before enabling? Maybe we can add an override enabled prop if that is the case
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.
Or does the use user hook look at the localStorage value before enabling?
the useUser
hook uses useAuth
to get the localStorage value (so there's a circular reference). To get around this I replaced useAuth
with useLocalStorage
in useUser
Maybe we can add an override enabled prop if that is the case
Ok! added this too
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.
ah, now it looks messy. i reviewed it without completely looking at the hook. suggest reverting haha ><. The previous code was more readable, and considering this is "throwaway" code i think we can get away with some duplication.
or we can set the state of isAuthenticated to be contingent on return value of useUser instead of the other way round:
export const useUser = (): UseUserReturn => {
const [isAuthenticated, setIsAuthenticated] = useLocalStorage<boolean>(LOGGED_IN_KEY)
const { data: user, isLoading } = useQuery<UserDto>(
userKeys.base,
() => fetchUser(),
// 10 minutes staletime, do not need to retrieve so often.
{
staleTime: 600000,
// Removed enabled state, just retrieve every 10 minutes
// new functions, update auth states
onSuccess: () => setIsAuthenticated(true),
onError: () => setIsAuthenticated(undefined) // remove login on error, may not be needed since we already have ApiService
},
)
return {
user: isAuthenticated ? user : undefined,
isLoading,
}
}
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.
haha it's ok! I will revert :) I think that option's the least messy / easiest to remove after the rollout
d017e2e
to
7a36e5a
Compare
7a36e5a
to
564142c
Compare
userKeys.base, | ||
() => fetchUser(), | ||
// 10 minutes staletime, do not need to retrieve so often. | ||
{ staleTime: 600000 }, |
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.
should we still add an onSuccess
to set localStorage to the authenticated state?
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.
oh yes good point! added
Problem
User appears logged out after switching from AngularJS to React
Closes #4287
Solution
/#!/forms
page, navigate to/workspace
user
to ascertain logged in stateBreaking Changes
Features:
Before & After Screenshots
BEFORE:
AFTER:
Tests
is-logged-in
is not present in localStorage.Log in to the AngularJS app. Click the banner message to switch to React.
You should be brought to the Workspace page (
/workspace
) on the React app and remain logged in.is-logged-in
in localStorage should have the valuetrue
v2-admin-ui
cookie should have the valuereact
.