···143143 .single();
144144 draft = data;
145145 existingDocUri = draft?.document;
146146+147147+ // If updating an existing document, verify the current user is the owner
148148+ if (existingDocUri) {
149149+ let docOwner = new AtUri(existingDocUri).host;
150150+ if (docOwner !== identity.atp_did) {
151151+ return {
152152+ success: false,
153153+ error: {
154154+ type: "oauth_session_expired" as const,
155155+ message: "Not the document owner",
156156+ did: identity.atp_did,
157157+ },
158158+ };
159159+ }
160160+ }
146161 }
147162148163 // Heuristic: Remove title entities if this is the first time publishing