diff --git a/src/app/api/chat/keys/route.ts b/src/app/api/chat/keys/route.ts index fcab630..87c6c69 100644 --- a/src/app/api/chat/keys/route.ts +++ b/src/app/api/chat/keys/route.ts @@ -21,6 +21,7 @@ export async function GET(request: NextRequest) { const bundle = await db.query.chatDeviceBundles.findFirst({ where: eq(chatDeviceBundles.did, did), + orderBy: (bundles, { desc }) => [desc(bundles.lastSeenAt)], }); console.log('[Chat Keys GET] Found local bundle:', bundle ? 'YES' : 'NO'); diff --git a/src/app/chat/page.tsx b/src/app/chat/page.tsx index 6640e0d..4b61de4 100644 --- a/src/app/chat/page.tsx +++ b/src/app/chat/page.tsx @@ -150,7 +150,7 @@ export default function ChatPage() { if (msg.isSentByMe && envelope.recipientDid) { // I'm the sender, so I need the recipient's public key to decrypt my own message try { - const keyRes = await fetch(`/api/chat/keys?did=${encodeURIComponent(envelope.recipientDid)}`); + const keyRes = await fetch(`/api/chat/keys?did=${encodeURIComponent(envelope.recipientDid)}`, { cache: 'no-store' }); if (keyRes.ok) { const keyData = await keyRes.json(); otherPartyPublicKey = keyData.publicKey; diff --git a/src/lib/hooks/useSodiumChat.ts b/src/lib/hooks/useSodiumChat.ts index ae5bcec..63cf649 100644 --- a/src/lib/hooks/useSodiumChat.ts +++ b/src/lib/hooks/useSodiumChat.ts @@ -64,7 +64,7 @@ export function useSodiumChat() { if (!user.did) { throw new Error('User DID not available'); } - const checkResponse = await fetch(`/api/chat/keys?did=${encodeURIComponent(user.did)}`); + const checkResponse = await fetch(`/api/chat/keys?did=${encodeURIComponent(user.did)}`, { cache: 'no-store' }); let shouldPublish = false;