[SDK] Validate and brand the persisted account did (#11387)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user