Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LogOut } from "lucide-react";
import { clearClientWalletState } from "@/lib/auth/clearClientWalletState";
import { useWallet } from "@meshsdk/react";
import { useRouter } from "next/router";
import { useUserStore } from "@/lib/zustand/user";
Expand Down Expand Up @@ -39,6 +40,8 @@ export default function LogoutWrapper({ mode, onAction }: LogoutWrapperProps) {
}

setPastWallet(undefined);
setPastUtxosEnabled(false);
clearClientWalletState();
router.push("/");
setTimeout(() => {
router.reload();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CircleUser, Copy, Unlink, LogOut, User } from "lucide-react";
import { clearClientWalletState } from "@/lib/auth/clearClientWalletState";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
Expand Down Expand Up @@ -199,6 +200,8 @@ export default function UserDropDownWrapper({
}

setPastWallet(undefined);
setPastUtxosEnabled(false);
clearClientWalletState();
router.push("/");
setTimeout(() => {
router.reload();
Expand Down
4 changes: 4 additions & 0 deletions src/components/common/overall-layout/user-drop-down.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CircleUser } from "lucide-react";
import { clearClientWalletState } from "@/lib/auth/clearClientWalletState";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
Expand All @@ -23,6 +24,7 @@ export default function UserDropDown() {
const { toast } = useToast();
const router = useRouter();
const setPastWallet = useUserStore((state) => state.setPastWallet);
const setPastUtxosEnabled = useUserStore((state) => state.setPastUtxosEnabled);
const userAddress = useUserStore((state) => state.userAddress);

const unlinkDiscordMutation = api.user.unlinkDiscord.useMutation({
Expand Down Expand Up @@ -151,6 +153,8 @@ export default function UserDropDown() {
}
disconnect();
setPastWallet(undefined);
setPastUtxosEnabled(false);
clearClientWalletState();
router.push("/");
setTimeout(() => {
router.reload();
Expand Down
15 changes: 15 additions & 0 deletions src/lib/auth/clearClientWalletState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Remove browser-side traces of the last connected wallet so that, after
* logout, nothing auto-reconnects and the user has to authorize again.
* Mesh persists the connected wallet under `mesh-wallet-persist`; the UTXOS
* store persists its network id under `utxos-state`.
*/
export function clearClientWalletState() {
if (typeof window === "undefined") return;
try {
localStorage.removeItem("mesh-wallet-persist");
localStorage.removeItem("utxos-state");
} catch (error) {
console.error("[Logout] Failed to clear persisted wallet state:", error);
}
}
7 changes: 7 additions & 0 deletions src/pages/api/auth/wallet-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { cors, addCorsCacheBustingHeaders } from "@/lib/cors";
import { DataSignature } from "@meshsdk/core";
import { checkSignature } from "@meshsdk/core-cst";
import {
clearWalletSessionCookie,
getWalletSessionFromReq,
setWalletSessionCookie,
type WalletSessionPayload,
Expand All @@ -17,6 +18,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return res.status(200).end();
}

// Logout: drop the session cookie so the next connect must re-authorize.
if (req.method === "DELETE") {
clearWalletSessionCookie(res);
return res.status(200).json({ ok: true });
}

if (req.method !== "POST") {
return res.status(405).json({ error: "Method Not Allowed" });
}
Expand Down
Loading