From 3aea959aa8350bb55a7045973af85fff1934d53f Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 5 Dec 2023 16:17:20 -0600 Subject: [PATCH] Fix session email/emailConfirmed types, update usage for safer access --- src/state/persisted/legacy.ts | 1 - src/state/persisted/schema.ts | 7 ++----- src/state/session/index.tsx | 4 ++-- src/view/com/modals/ChangeEmail.tsx | 4 ++-- src/view/com/modals/VerifyEmail.tsx | 6 +++--- src/view/screens/Settings.tsx | 2 +- src/view/shell/desktop/RightNav.tsx | 4 ++-- 7 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/state/persisted/legacy.ts b/src/state/persisted/legacy.ts index 0258775299..012f980b73 100644 --- a/src/state/persisted/legacy.ts +++ b/src/state/persisted/legacy.ts @@ -66,7 +66,6 @@ type LegacySchema = { const DEPRECATED_ROOT_STATE_STORAGE_KEY = 'root' -// TODO remove, assume that partial data may be here during our refactor export function transform(legacy: Partial): Schema { return { colorMode: legacy.shell?.colorMode || defaults.colorMode, diff --git a/src/state/persisted/schema.ts b/src/state/persisted/schema.ts index 71f9bd545f..5ed8e01f34 100644 --- a/src/state/persisted/schema.ts +++ b/src/state/persisted/schema.ts @@ -2,17 +2,14 @@ import {z} from 'zod' import {deviceLocales} from '#/platform/detection' // only data needed for rendering account page -// TODO agent.resumeSession requires the following fields const accountSchema = z.object({ service: z.string(), did: z.string(), handle: z.string(), - email: z.string(), - emailConfirmed: z.boolean(), + email: z.string().optional(), + emailConfirmed: z.boolean().optional(), refreshJwt: z.string().optional(), // optional because it can expire accessJwt: z.string().optional(), // optional because it can expire - // displayName: z.string().optional(), - // aviUrl: z.string().optional(), }) export type PersistedAccount = z.infer diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx index e6def1fab9..37454187a2 100644 --- a/src/state/session/index.tsx +++ b/src/state/session/index.tsx @@ -245,7 +245,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { service: agent.service.toString(), did: agent.session.did, handle: agent.session.handle, - email: agent.session.email!, // TODO this is always defined? + email: agent.session.email, emailConfirmed: agent.session.emailConfirmed || false, refreshJwt: agent.session.refreshJwt, accessJwt: agent.session.accessJwt, @@ -342,7 +342,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { service: agent.service.toString(), did: agent.session.did, handle: agent.session.handle, - email: agent.session.email!, // TODO this is always defined? + email: agent.session.email, emailConfirmed: agent.session.emailConfirmed || false, refreshJwt: agent.session.refreshJwt, accessJwt: agent.session.accessJwt, diff --git a/src/view/com/modals/ChangeEmail.tsx b/src/view/com/modals/ChangeEmail.tsx index 73ab33dd45..44b102fa0b 100644 --- a/src/view/com/modals/ChangeEmail.tsx +++ b/src/view/com/modals/ChangeEmail.tsx @@ -118,8 +118,8 @@ export function Component() { ) : stage === Stages.ConfirmCode ? ( An email has been sent to your previous address,{' '} - {currentAccount?.email || ''}. It includes a confirmation code - which you can enter below. + {currentAccount?.email || '(no email)'}. It includes a + confirmation code which you can enter below. ) : ( diff --git a/src/view/com/modals/VerifyEmail.tsx b/src/view/com/modals/VerifyEmail.tsx index 4376a3e450..786a814a76 100644 --- a/src/view/com/modals/VerifyEmail.tsx +++ b/src/view/com/modals/VerifyEmail.tsx @@ -108,8 +108,8 @@ export function Component({showReminder}: {showReminder?: boolean}) { ) : stage === Stages.ConfirmCode ? ( - An email has been sent to {currentAccount?.email || ''}. It - includes a confirmation code which you can enter below. + An email has been sent to {currentAccount?.email || '(no email)'}. + It includes a confirmation code which you can enter below. ) : ( '' @@ -125,7 +125,7 @@ export function Component({showReminder}: {showReminder?: boolean}) { size={16} /> - {currentAccount?.email || ''} + {currentAccount?.email || '(no email)'} )} - {currentAccount.email}{' '} + {currentAccount.email || '(no email)'}{' '} openModal({name: 'change-email'})}> diff --git a/src/view/shell/desktop/RightNav.tsx b/src/view/shell/desktop/RightNav.tsx index 9a51865496..c8196c2c4b 100644 --- a/src/view/shell/desktop/RightNav.tsx +++ b/src/view/shell/desktop/RightNav.tsx @@ -58,8 +58,8 @@ export function DesktopRightNav() { type="md" style={pal.link} href={FEEDBACK_FORM_URL({ - email: currentAccount!.email, - handle: currentAccount!.handle, + email: currentAccount?.email, + handle: currentAccount?.handle, })} text={_(msg`Feedback`)} />