From d633a12be9c95024b3068cabb1119d1d838c7ce8 Mon Sep 17 00:00:00 2001 From: Calli Date: Mon, 20 May 2024 21:41:48 +0300 Subject: [PATCH] upsert character on login --- src/app/page.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index 3d11ceb..51c49ea 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -78,7 +78,13 @@ const Home = () => { if (code) { window.history.replaceState(null, "", "/"); const res = await fetch(`api/token?code=${code}`); - return [...characters, await res.json()]; + const newCharacter: AccessToken = await res.json(); + return [ + ...characters.filter( + (c) => c.character.characterId !== newCharacter.character.characterId, + ), + newCharacter, + ]; } return Promise.resolve(characters); };