Embed signing with Vue (v2)
Embed the signing page in a Vue or Nuxt app with the SigningEmbed component from @sajn/embed-vue
Embedding v2 is in beta. Embed sessions and SDK 1.0 can change in ways that break your integration before the first stable release, estimated for November 2026. Embedding v1, described in Embedded signing, is stable.
In this guide, you embed the sajn signing page in a Vue app with the SigningEmbed component from @sajn/embed-vue. The component wraps createSigningEmbed from @sajn/embed-js.
Before you begin
- Turn on embedding for your organization and add your domain to the embed domains. For more information, see Add your embed domains.
- Create and send the document, and note the party's
id. For the steps, see Embed the signing page. - Vue 3.3 or later.
Install the package
npm install @sajn/embed-vue@1.0.0-beta.2Create a session on your server
Your Vue code never calls the sajn API. Add a server endpoint that creates an embed session and returns its clientSecret. In Nuxt, use a server route:
// server/api/sajn/embed-session.post.ts
export default defineEventHandler(async (event) => {
// Replace with your own auth and your own lookup of the document and party.
const user = await requireSignedInUser(event);
const { documentId, partyId } = await findSigningForUser(user.id);
const session = await $fetch<{ clientSecret: string }>("https://app.sajn.se/api/v1/embed-sessions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.SAJN_API_KEY}`,
"Sajn-Version": "2026-10",
},
body: { documentId, partyId, origins: ["https://app.example.com"] },
});
return { clientSecret: session.clientSecret };
});The component calls this endpoint again each time a session ends, so create a new session on every call. For every field of the request, see Create session request.
Show the signing page
Render SigningEmbed with a fetch-client-secret function:
<script setup lang="ts">
import { SigningEmbed } from "@sajn/embed-vue";
import type { EmbedIds, SigningEmbedError } from "@sajn/embed-vue";
async function fetchClientSecret() {
const { clientSecret } = await $fetch<{ clientSecret: string }>("/api/sajn/embed-session", { method: "POST" });
return clientSecret;
}
function handleSigned({ documentId }: EmbedIds) {
navigateTo(`/signed?doc=${documentId}`);
}
function handleError({ code, message }: SigningEmbedError) {
console.error(code, message);
}
</script>
<template>
<SigningEmbed
class="signing"
:fetch-client-secret="fetchClientSecret"
@signed="handleSigned"
@error="handleError"
/>
</template>
<style scoped>
.signing {
height: 80vh;
}
</style>The component renders a div that holds the frame. A class or style attribute applies to that div, so give it a height there. The component creates the frame when it mounts in the browser, so server rendering in Nuxt outputs only the empty div.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
fetch-client-secret | () => Promise<string> | Required | Calls your server and returns a new clientSecret. Called again whenever a session ends. |
host | string | https://app.sajn.se | The sajn host. Sandboxes use the default. |
appearance | Appearance | None | Cosmetic values on top of the session's appearance. See Appearance. |
locale | Locale | The session's locale | The frame's language: sv, en, no, da, fi, de, is, es, fr, or it. |
title | string | Signera dokument | The frame's accessible name. |
fallback-height | string | 600px | The frame's height in fixed mode when the container has no height of its own. |
bootstrap-timeout-ms | number | 10000 | How long the SDK waits for fetchClientSecret and the frame's answer before it raises bootstrap_timeout. |
open-url | (url: string) => void | None | Opens eID pages and the BankID app link yourself. Set it where the frame can't open a window, such as a native app's web view. Without it, the frame opens them on its own. |
Events
| Event | Payload |
|---|---|
@ready | EmbedReady: EmbedIds and loadMs |
@signed | EmbedIds |
@rejected | EmbedIds and reasonGiven |
@fields-submitted | EmbedIds |
@verified | EmbedIds |
@state-change | EmbedState |
@resize | The height in pixels |
@session-expired | None |
@error | SigningEmbedError: code and message |
For when each event fires, see Events. EmbedIds is { documentId: string; partyId: string; externalId: string | null }.
Update the frame
The component watches appearance and locale, and a change updates the open frame without reloading it:
<SigningEmbed
:fetch-client-secret="fetchClientSecret"
:appearance="{ colorScheme: isDark ? 'dark' : 'light', colors: { primary: '#0f766e' } }"
:locale="language"
/>To ask the frame for a new EmbedState, which arrives in @state-change, call requestState() on a template ref to the component.
The component reads host, title, and fallback-height only when it mounts. To apply a change to one of them, change the component's key, which mounts a new frame with a new session. Features can't change from the browser. To change them, create a new session.
TypeScript types
The package exports its types:
import type {
Appearance,
EmbedErrorCode,
EmbedIds,
EmbedState,
Locale,
PartyStatus,
SigningEmbedError,
} from "@sajn/embed-vue";Troubleshooting
@errorgetsbootstrap_timeout, and the frame is blank: the browser most likely refused the frame. Check the session'soriginsagainst the page's exact origin, and your page's ownframe-srcpolicy. For every cause, see Fix a blank frame.@errorgetsclient_secret_failed: thefetch-client-secretfunction threw an error, or returned something other than theclientSecretstring.- The frame is 600px high and doesn't fill the container: the container has no height. Set one with
classorstyle.
For the other error codes, see Error codes.
Next steps
Was this page helpful?
Last updated on