about summary refs log tree commit diff
path: root/src/state/session/index.tsx
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-05-03 02:52:37 +0100
committerGitHub <noreply@github.com>2024-05-03 02:52:37 +0100
commitc13685a0cf5a5c4266154495a3cb10f0f76d84dc (patch)
treef1938706f41638317e7c7e8993bf490c758fcb0f /src/state/session/index.tsx
parent0f827c321370f26b0c1c8db7286ad9be7e6ac98a (diff)
downloadvoidsky-c13685a0cf5a5c4266154495a3cb10f0f76d84dc.tar.zst
[Session] Fix stale emailAuthFactor and emailConfirmed on the client (#3835)
* Fix account refresh to not clobber falsy values

* Use ?? in more places
Diffstat (limited to 'src/state/session/index.tsx')
-rw-r--r--src/state/session/index.tsx26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx
index 8ad244c8b..b4799e2f7 100644
--- a/src/state/session/index.tsx
+++ b/src/state/session/index.tsx
@@ -121,11 +121,11 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
       // TODO: use agentToSessionAccount for this too.
       const refreshedAccount: SessionAccount = {
         service: account.service,
-        did: session?.did || account.did,
-        handle: session?.handle || account.handle,
-        email: session?.email || account.email,
-        emailConfirmed: session?.emailConfirmed || account.emailConfirmed,
-        emailAuthFactor: session?.emailAuthFactor || account.emailAuthFactor,
+        did: session?.did ?? account.did,
+        handle: session?.handle ?? account.handle,
+        email: session?.email ?? account.email,
+        emailConfirmed: session?.emailConfirmed ?? account.emailConfirmed,
+        emailAuthFactor: session?.emailAuthFactor ?? account.emailAuthFactor,
         deactivated: isSessionDeactivated(session?.accessJwt),
         pdsUrl: agent.pdsUrl?.toString(),
 
@@ -311,8 +311,8 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
         isSessionDeactivated(account.accessJwt) || account.deactivated
 
       const prevSession = {
-        accessJwt: account.accessJwt || '',
-        refreshJwt: account.refreshJwt || '',
+        accessJwt: account.accessJwt ?? '',
+        refreshJwt: account.refreshJwt ?? '',
         did: account.did,
         handle: account.handle,
       }
@@ -457,16 +457,12 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
 
         const updatedAccount = {
           ...currentAccount,
-          handle: account.handle || currentAccount.handle,
-          email: account.email || currentAccount.email,
+          handle: account.handle ?? currentAccount.handle,
+          email: account.email ?? currentAccount.email,
           emailConfirmed:
-            account.emailConfirmed !== undefined
-              ? account.emailConfirmed
-              : currentAccount.emailConfirmed,
+            account.emailConfirmed ?? currentAccount.emailConfirmed,
           emailAuthFactor:
-            account.emailAuthFactor !== undefined
-              ? account.emailAuthFactor
-              : currentAccount.emailAuthFactor,
+            account.emailAuthFactor ?? currentAccount.emailAuthFactor,
         }
 
         return {