[SDK] Validate and brand the persisted account did (#11387)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-13 22:26:22 +03:00
committed by GitHub
parent 9fe0084874
commit 3677c98873
46 changed files with 154 additions and 205 deletions
+12 -1
View File
@@ -1,3 +1,4 @@
import {isDidString} from '@atproto/lex'
import {z} from 'zod'
import {deviceLanguageCodes, deviceLocales} from '#/locale/deviceLocales'
@@ -13,7 +14,17 @@ const externalEmbedOptions = ['show', 'hide'] as const
*/
const accountSchema = z.object({
service: z.string(),
did: z.string(),
/**
* Genuinely validated, not just branded: the refinement rejects malformed
* values at runtime and narrows the inferred type to `DidString`.
*
* Weigh any further tightening of this field carefully. One failing field
* fails the whole root schema, and {@link tryParse} then discards the ENTIRE
* persisted state - every account and every preference - so the app boots
* logged out with defaults. Persisted dids come from com.atproto.server
* responses and are always canonical, so this particular check is safe.
*/
did: z.string().refine(isDidString),
handle: z.string(),
email: z.string().optional(),
emailConfirmed: z.boolean().optional(),