Skip to Content
Embedding

Embed signing with Vue

Embed the signing page in a Vue or Nuxt app with the @sajn/embed-vue component

In this guide, you embed the sajn signing page in a Vue app with the @sajn/embed-vue package. The @sajn/embed-vue package provides a Vue 3 component for embedding the signing experience.

Before you begin

  • Turn on embedding for your organization and add your domain to the allowlist. For more information, see Embedded signing.
  • On your server, create the document and read the party's token from the signingUrl that GET /api/v1/documents/DOCUMENT_ID/parties/PARTY_ID returns. For the steps, see Embed the signing page. Never call the sajn API from the browser, because the request needs your API key.

Requirements

  • Vue 3.3.0+

Installation

npm install @sajn/embed-vue

Component

Import

<script setup>
import { EmbedSignDocument } from '@sajn/embed-vue';
</script>

Props

PropTypeRequiredDefaultDescription
document-idstringYes-Document ID
tokenstringYes-The party's token
hoststringNohttps://app.sajn.seCustom host URL
languagestringNoenUI language (sv, en, no, da, fi, de, is, es, fr, it)
classstringNo-CSS class for iframe
css-varsCssVarsNo-Theme customization
allow-document-rejectionbooleanNofalseEnable rejection
show-scroll-indicatorbooleanNotrueShow scroll indicator
signature-input-modesstring[]NoallWhich of draw, type, upload the signature pad offers
show-document-idbooleanNotrueShow the document ID under the sign button
additional-propsobjectNo-Additional options

Events

EventPayloadDescription
document-ready-Iframe loaded and ready
signer-completedSignerCompletedDataSigning completed
variables-submittedVariablesSubmittedDataForm fields submitted; signing opens once every filler is done
signer-rejectedSignerRejectedDataDocument rejected
document-errorDocumentErrorDataError occurred

Basic example

<script setup>
import { EmbedSignDocument } from '@sajn/embed-vue';

const props = defineProps<{
  documentId: string;
  token: string;
}>();

function handleComplete(data) {
  console.log('Document signed!', data);
}
</script>

<template>
  <div class="signing-container">
    <EmbedSignDocument
      :document-id="props.documentId"
      :token="props.token"
      @signer-completed="handleComplete"
    />
  </div>
</template>

<style scoped>
.signing-container {
  width: 100%;
  height: 100vh;
}
</style>

Example with every prop

<script setup lang="ts">
import { EmbedSignDocument } from '@sajn/embed-vue';
import type { SignerCompletedData, SignerRejectedData } from '@sajn/embed-vue';

const props = defineProps<{
  documentId: string;
  token: string;
}>();

const cssVars = {
  primary: '#2563eb',
  background: '#ffffff',
  foreground: '#1f2937',
  mutedForeground: '#6b7280',
};

function handleReady() {
  console.log('Signing interface loaded');
}

function handleComplete(data: SignerCompletedData) {
  if (data.failed) {
    console.error('Signing failed:', data.failed);
    return;
  }
  console.log('Document signed successfully!');
  // Navigate to success page
}

function handleRejected(data: SignerRejectedData) {
  console.log('Document rejected:', data.reason);
}

function handleError(error: { code: string; message: string }) {
  console.error('Error:', error.code, error.message);
}
</script>

<template>
  <div class="signing-container">
    <EmbedSignDocument
      :document-id="props.documentId"
      :token="props.token"
      :css-vars="cssVars"
      :allow-document-rejection="true"
      class="signing-iframe"
      @document-ready="handleReady"
      @signer-completed="handleComplete"
      @signer-rejected="handleRejected"
      @document-error="handleError"
    />
  </div>
</template>

<style scoped>
.signing-container {
  width: 100%;
  height: 100vh;
}

.signing-iframe {
  border-radius: 8px;
  overflow: hidden;
}
</style>

TypeScript types

The package exports all types:

import type {
  SignerCompletedData,
  SignerRejectedData,
  SignatureInputMode,
  Language,
  CssVars,
} from '@sajn/embed-vue';

SignerCompletedData

interface SignerCompletedData {
  token: string;
  documentId: string;
  signerId: string;
  failed?: string;  // Present if signing failed
}

SignerRejectedData

interface SignerRejectedData {
  token: string;
  documentId: string;
  signerId: string;
  reason: string;
}

CssVars

type CssVars = {
  background?: string;
  primary?: string;
  foreground?: string;
  mutedForeground?: string;
}

Nuxt

The component works with Nuxt 3 projects:

<!-- pages/sign/[id].vue -->
<script setup lang="ts">
import { EmbedSignDocument } from '@sajn/embed-vue';

const route = useRoute();
const documentId = route.params.id as string;

// Your endpoint returns the token you stored when you sent the document.
const { data: token } = await useFetch(`/api/sign/${documentId}/token`);

function handleComplete() {
  navigateTo('/thank-you');
}
</script>

<template>
  <div class="signing-page">
    <EmbedSignDocument
      v-if="token"
      :document-id="documentId"
      :token="token"
      @signer-completed="handleComplete"
    />
  </div>
</template>

<style scoped>
.signing-page {
  height: 100vh;
}
</style>

Styling

The component renders an iframe that fills its container. Set dimensions on the parent element:

.signing-container {
  width: 100%;
  height: 600px;
  /* or */
  height: 100vh;
}

The iframe has no border by default and is set to width: 100% and height: 100%.

View a signed document

The package also includes EmbedViewDocument for displaying signed documents in read-only mode.

Import

<script setup>
import { EmbedViewDocument } from '@sajn/embed-vue';
</script>

Props

PropTypeRequiredDefaultDescription
document-idstringYes-Document ID
tokenstringYes-The party's token, the same as for signing
hoststringNohttps://app.sajn.seCustom host URL
languagestringNoenUI language (sv, en, no, da, fi, de, is, es, fr, it)
classstringNo-CSS class for iframe
css-varsCssVarsNo-Theme customization
show-scroll-indicatorbooleanNotrueShow scroll indicator
additional-propsobjectNo-Additional options

Events

EventPayloadDescription
document-ready-Iframe loaded and ready
document-errorDocumentErrorDataError occurred

Example

<script setup lang="ts">
import { EmbedViewDocument } from '@sajn/embed-vue';

const props = defineProps<{
  documentId: string;
  token: string;
}>();

function handleReady() {
  console.log('Document loaded');
}

function handleError(error: { code: string; message: string }) {
  console.error('Error:', error.code, error.message);
}
</script>

<template>
  <div class="viewer-container">
    <EmbedViewDocument
      :document-id="props.documentId"
      :token="props.token"
      :css-vars="{
        primary: '#2563eb',
        background: '#ffffff',
      }"
      @document-ready="handleReady"
      @document-error="handleError"
    />
  </div>
</template>

<style scoped>
.viewer-container {
  width: 100%;
  height: 100vh;
}
</style>

Next steps

Embedded signing

See the shared options, events, and security model.

Embed signing in your app

Run the whole flow from server to iframe.

Was this page helpful?

Last updated on