Skip to content

Commit 92716c2

Browse files
committed
fix: connectembed siwe auth revalidation
1 parent 1cd11a8 commit 92716c2

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

.changeset/tall-melons-sneeze.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix revalidation with siwe auth in ConnectEmbed

packages/thirdweb/src/react/core/hooks/auth/useSiweAuth.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2+
import { useEffect } from "react";
23
import type { LoginPayload } from "../../../../auth/core/types.js";
34
import type { VerifyLoginPayloadParams } from "../../../../auth/core/verify-login-payload.js";
45
import { getCachedChain } from "../../../../chains/utils.js";
@@ -56,6 +57,13 @@ export function useSiweAuth(
5657

5758
const queryClient = useQueryClient();
5859

60+
// We need to reset the react query cache on mount for components like ConnectEmbed that are unmount and remount depending on the auth / connection state
61+
useEffect(() => {
62+
queryClient.invalidateQueries({
63+
queryKey: ["siwe_auth"],
64+
});
65+
}, [queryClient]);
66+
5967
const isLoggedInQuery = useQuery({
6068
queryKey: ["siwe_auth", "isLoggedIn", activeAccount?.address],
6169
enabled: requiresAuth && !!activeAccount?.address,
@@ -71,7 +79,7 @@ export function useSiweAuth(
7179
});
7280

7381
const loginMutation = useMutation({
74-
mutationKey: ["siwe_auth", "login"],
82+
mutationKey: ["siwe_auth", "login", activeAccount?.address],
7583
mutationFn: async () => {
7684
if (!authOptions) {
7785
throw new Error("No auth options provided");
@@ -117,7 +125,7 @@ export function useSiweAuth(
117125
});
118126

119127
const logoutMutation = useMutation({
120-
mutationKey: ["siwe_auth", "logout"],
128+
mutationKey: ["siwe_auth", "logout", activeAccount?.address],
121129
mutationFn: async () => {
122130
if (!authOptions) {
123131
throw new Error("No auth options provided");

0 commit comments

Comments
 (0)