diff --git a/docs/embed-sdk/v0.md b/docs/embed-sdk/v0.md index c415d40..9b3d2ab 100644 --- a/docs/embed-sdk/v0.md +++ b/docs/embed-sdk/v0.md @@ -175,6 +175,27 @@ const rkey = uri.split('/').pop(); Blento.notifyNavigate(`/${session.did}/event/r/${rkey}`); ``` +### `Blento.promptLogin(): void` + +Ask the parent to show its login modal. Fire-and-forget — there is no +returned Promise. To detect when the user has signed in, subscribe to +`session` events: + +```js +if (!Blento.getSession()) { + const off = Blento.on('session', (s) => { + if (s) { + off(); + doTheThing(); + } + }); + Blento.promptLogin(); +} +``` + +Calling `promptLogin()` while the user is already signed in is a no-op from +the iframe's perspective; the parent may still display the modal. + ## Errors All write rejections are `BlentoError` instances with a stable `.code`: @@ -213,8 +234,9 @@ implement directly. All messages include `v: 0`. { v: 0, id, type: 'deleteRecord', payload: { collection, rkey } } { v: 0, id, type: 'applyWrites', payload: { writes, validate? } } { v: 0, id, type: 'uploadBlob', payload: { bytes: number[], mimeType } } -{ v: 0, type: 'blento:resize', heightPx } // unsolicited -{ v: 0, type: 'blento:navigate', url } // unsolicited +{ v: 0, type: 'blento:resize', heightPx } // unsolicited +{ v: 0, type: 'blento:navigate', url } // unsolicited +{ v: 0, type: 'blento:promptLogin' } // unsolicited ``` `id` is any unique string you generate — the parent echoes it on the response. diff --git a/src/lib/embed/AtmoEmbed.svelte b/src/lib/embed/AtmoEmbed.svelte index 7f4ed2c..7cc3490 100644 --- a/src/lib/embed/AtmoEmbed.svelte +++ b/src/lib/embed/AtmoEmbed.svelte @@ -3,6 +3,7 @@ import { browser } from '$app/environment'; import { page } from '$app/state'; import { user } from '$lib/atproto'; + import { atProtoLoginModalState } from '$lib/atproto/LoginModal.svelte'; import { embedApplyWrites, embedCreateRecord, @@ -201,6 +202,11 @@ return; } + if (data.type === 'blento:promptLogin') { + atProtoLoginModalState.show(); + return; + } + if (typeof data.id === 'string' && typeof data.type === 'string') { handleRequest(data.id, data.type, data.payload); } diff --git a/static/embed/v0/sdk.js b/static/embed/v0/sdk.js index 5ad79d0..1ab4bd6 100644 --- a/static/embed/v0/sdk.js +++ b/static/embed/v0/sdk.js @@ -14,8 +14,9 @@ * { v: 0, id, type: 'deleteRecord', payload: { collection, rkey } } * { v: 0, id, type: 'applyWrites', payload: { writes, validate? } } * { v: 0, id, type: 'uploadBlob', payload: { bytes: number[], mimeType } } - * { v: 0, type: 'blento:resize', heightPx } - * { v: 0, type: 'blento:navigate', url } + * { v: 0, type: 'blento:resize', heightPx } + * { v: 0, type: 'blento:navigate', url } + * { v: 0, type: 'blento:promptLogin' } * * ─── Wire protocol (parent → iframe) ───────────────────────────────────────── * { v: 0, type: 'ready', session } // sent once after handshake @@ -202,6 +203,9 @@ }, notifyNavigate: function (url) { sendToParent({ v: PROTOCOL_VERSION, type: 'blento:navigate', url: url }); + }, + promptLogin: function () { + sendToParent({ v: PROTOCOL_VERSION, type: 'blento:promptLogin' }); } }; diff --git a/static/embed/v0/test.html b/static/embed/v0/test.html index 44e8e4e..19b652d 100644 --- a/static/embed/v0/test.html +++ b/static/embed/v0/test.html @@ -130,6 +130,7 @@
+
@@ -249,6 +250,11 @@ show('notifyNavigate(/) sent', null); }; + $('btn-prompt-login').onclick = () => { + window.Blento.promptLogin(); + show('promptLogin() sent', null); + }; + if (window.Blento.getTheme().dark) { document.documentElement.classList.add('dark'); }