MCPcopy Index your code
hub / github.com/coder/coder / logout

Function logout

site/src/api/queries/users.ts:220–256  ·  view source on GitHub ↗
(queryClient: QueryClient)

Source from the content-addressed store, hash-verified

218};
219
220export const logout = (queryClient: QueryClient): MutationOptions => {
221 return {
222 mutationFn: API.logout,
223 // We're doing this cleanup in `onSettled` instead of `onSuccess` because in the case where an oAuth refresh token has expired this endpoint will return a 401 instead of 200.
224 onSettled: (_, error) => {
225 if (error) {
226 console.error(error);
227 }
228
229 /**
230 * 2024-05-02 - If we persist any form of user data after the user logs
231 * out, that will continue to seed the React Query cache, creating
232 * "impossible" states where we'll have data we're not supposed to have.
233 *
234 * This has caused issues where logging out will instantly throw a
235 * completely uncaught runtime rendering error. Worse yet, the error only
236 * exists when serving the site from the Go backend (the JS environment
237 * has zero issues because it doesn't have access to the metadata). These
238 * errors can only be caught with E2E tests.
239 *
240 * Deleting the user data will mean that all future requests have to take
241 * a full roundtrip, but this still felt like the best way to ensure that
242 * manually logging out doesn't blow the entire app up.
243 *
244 * 2025-08-20 - Since this endpoint is for performing a post logout clean up
245 * on the backend we should move this local clean up outside of the mutation
246 * so that it can be explicitly performed even in cases where we don't want
247 * run the clean up (e.g. when a user is unauthorized). Unfortunately our
248 * auth logic is too tangled up with some obscured React Query behaviors to
249 * be able to move right now. After `AuthProvider.tsx` is refactored this
250 * should be moved.
251 */
252 defaultMetadataManager.clearMetadataByKey("user");
253 queryClient.removeQueries();
254 },
255 };
256};
257
258export const updateProfile = (userId: string) => {
259 return {

Callers 1

AuthProviderFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected