Skip to content
Closed
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
5 changes: 5 additions & 0 deletions packages/keychain/src/components/disconnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export const Disconnect = () => {
(async () => {
if (!controller || isDone) return;
await controller.disconnect();
try {
localStorage.clear();
} catch {
// Ignore if localStorage is unavailable
}
setIsDone(true);
if (urlSearchParams) {
const redirectUrl = urlSearchParams.get("redirect_url");
Expand Down
12 changes: 12 additions & 0 deletions packages/keychain/src/hooks/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@ export function useConnectionValue() {

(async () => {
await controller.disconnect();
try {
localStorage.clear();
} catch {
// Ignore if localStorage is unavailable
}
setController(undefined);
})();
}, [controller, urlRpcUrl, setController, setRpcUrl]);
Expand Down Expand Up @@ -854,6 +859,13 @@ export function useConnectionValue() {

const logout = useCallback(async () => {
await window.controller?.disconnect();
// Clear localStorage directly to handle storage partition mismatches
// caused by requestStorageAccess() switching contexts
try {
localStorage.clear();
} catch {
// Ignore if localStorage is unavailable
}
window.location.reload();
if (parent) {
parent.close();
Expand Down
18 changes: 16 additions & 2 deletions packages/keychain/src/utils/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,28 @@ export function connectToController<
disconnect: () => async () => {
// First clear the React state
setController(undefined);
// Then cleanup the controller
// Then cleanup the controller (WASM clears its storage backend)
await window.controller?.disconnect();
// Also clear localStorage directly from JS to handle storage partition
// mismatches caused by requestStorageAccess() switching between
// partitioned and unpartitioned storage contexts.
try {
localStorage.clear();
} catch {
// Ignore if localStorage is unavailable
}
},
logout: () => async () => {
// First clear the React state
setController(undefined);
// Then cleanup the controller
// Then cleanup the controller (WASM clears its storage backend)
await window.controller?.disconnect();
// Also clear localStorage directly from JS (see disconnect above)
try {
localStorage.clear();
} catch {
// Ignore if localStorage is unavailable
}
},
username: () => () => window.controller?.username(),
delegateAccount: () => () => window.controller?.delegateAccount(),
Expand Down
Loading