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

Remove cached data when logging out #1815

Merged
merged 1 commit into from
Apr 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion frontend/src/pages/mock/logout.page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NextPage } from "next";
import { useRouter } from "next/router";
import { MouseEventHandler } from "react";
import { useSWRConfig } from "swr";
import { getRuntimeConfig } from "../../config";
import { authenticatedFetch } from "../../hooks/api/api";
import { useProfiles } from "../../hooks/api/profile";
Expand All @@ -11,6 +12,7 @@ const MockLogout: NextPage = () => {
const router = useRouter();
const profiles = useProfiles();
const users = useUsers();
const { cache } = useSWRConfig();

const onLogout: MouseEventHandler = async (event) => {
event.preventDefault();
Expand All @@ -23,7 +25,11 @@ const MockLogout: NextPage = () => {
method: "GET",
redirect: "manual",
});
// Revalidate account data to reflect logged out status:
// Revalidate account data to reflect logged out status.
// Note that the `clear` method exists, even though it's not exposed on the
// type yet:
// https://github.com/vercel/swr/issues/161#issuecomment-1079198998
Copy link
Member

Choose a reason for hiding this comment

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

praise: thanks for sending a PR upstream! I subscribed to it to hopefully help remember when we can remove this work-around.

(cache as unknown as { clear: () => void }).clear();
await profiles.mutate();
await users.mutate();

Expand Down