-
Notifications
You must be signed in to change notification settings - Fork 901
fix: resolve User is not unauthenticated error seen on logout #10349
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,8 @@ import { | |
GetUsersResponse, | ||
UpdateUserPasswordRequest, | ||
UpdateUserProfileRequest, | ||
User, | ||
UsersRequest, | ||
} from "api/typesGenerated"; | ||
import { getMetadataAsJSON } from "utils/metadata"; | ||
import { getAuthorizationKey } from "./authCheck"; | ||
|
||
export const users = (req: UsersRequest): UseQueryOptions<GetUsersResponse> => { | ||
|
@@ -89,21 +87,11 @@ export const authMethods = () => { | |
}; | ||
}; | ||
|
||
const initialMeData = getMetadataAsJSON<User>("user"); | ||
const meKey = ["me"] as const; | ||
|
||
export const me = (queryClient: QueryClient) => { | ||
export const me = () => { | ||
return { | ||
queryKey: meKey, | ||
queryFn: async () => { | ||
const cachedData = queryClient.getQueryData(meKey); | ||
if (cachedData === undefined && initialMeData !== undefined) { | ||
return initialMeData; | ||
} | ||
|
||
return API.getAuthenticatedUser(); | ||
}, | ||
} satisfies UseQueryOptions<User>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm... @Parkreiner @Kira-Pilot maybe we should do something different like: return {
queryKey: meKey,
initialData: initialMe,
queryFn: API.getAuthenticatedUser,
} Because if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah...This works perfectly. I double-checked the React Query type definitions, and somehow missed that initialData had an extra I'm going to make another PR simplifying all the other functions that work like this |
||
queryKey: ["me"], | ||
queryFn: async () => API.getAuthenticatedUser(), | ||
}; | ||
}; | ||
|
||
export const hasFirstUser = () => { | ||
|
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.
Can I get a gut check here that this is safe to take out?? Seems fine but I am not very familiar with these tags and I don't want to break anything.
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.
This shouldn't be taken out! It makes the page load faster. See:
coder/site/site.go
Lines 302 to 307 in 21f8731
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.
@kylecarbs @BrunoQuaresma Gotcha! So if I understand correctly, we return some API responses when the user requests
index.html
. This is achieved via thesemeta
tags.I see this pattern some places in the app:
getMetadataAsJSON<Entitlements>("entitlements") ?? API.getEntitlements()
And I'm confused because 1) wouldn't we always want fresh entitlement data? and 2) don't we already load entitlement data again in our
DashboardProvider
which wraps all authenticated routes?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.
Whenever the user loads
index.html
(e.g. you navigate to dev.coder.com), that would provide fresh entitlement data. It's similar to making the request from the FE, we just do it on page load.The
DashboardProvider
re-fetching it would be a bug in that 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.
Ok, but given this pattern:
async () => getMetadataAsJSON<User>("user") ?? API.getAuthenticatedUser(),
if a user doesn't refresh the page between login and logout, I think we'll see this bug because the user request is never rehydrated, right