Skip to content

Commit

Permalink
app: signout backend when we detect wallet switch (#330)
Browse files Browse the repository at this point in the history
* app: signout backend when we detect wallet switch

* remove code duplication
  • Loading branch information
kahkeng authored Jul 14, 2023
1 parent e6a22ce commit 8092384
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/utils/rainbowSIWEmod/RainbowKitSiweNextAuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,21 @@ export function RainbowKitSiweNextAuthProvider({
const { data: session, status } = useSession();
const { address: account } = useAccount();

const signoutSequence = async () => {
// signout on frontend first, so that we don't end up in situation
// where frontend is signed in but backend is signed out, which will
// be confusing to the user
await signOut({ redirect: false });
if (getSignoutCallback) {
await getSignoutCallback();
}
};

/* force logout if account changes */
useEffect(() => {
if (session && session.user?.name !== account) signOut({ redirect: false });
if (session && session.user?.name !== account) {
signoutSequence();
}
}, [account, session]);

const adapter = useMemo(
Expand Down Expand Up @@ -82,15 +94,7 @@ export function RainbowKitSiweNextAuthProvider({
return nonce;
},

signOut: async () => {
// signout on frontend first, so that we don't end up in situation
// where frontend is signed in but backend is signed out, which will
// be confusing to the user
await signOut({ redirect: false });
if (getSignoutCallback) {
await getSignoutCallback();
}
},
signOut: signoutSequence,

verify: async ({ message, signature }) => {
const messageJson = JSON.stringify(message);
Expand Down

0 comments on commit 8092384

Please sign in to comment.