Complete document creation and signing process for Angular SaaS

1

Generate JWT on your back-end to authorize users

Prerequisites:

Sign Up and Obtain API Key: Visit DocuSeal API Console to obtain your API key.

JWT (JSON Web Token) serves as a secure means to authorize your individual SaaS users with the DocuSeal document form builder. The token is generated with JWT payload parameters to grant access only for your specific SaaS user and only for a specific document:

  • user_email: Email address of the DocuSeal admin user that provided the API_KEY for JWT signing.
  • integration_email: Email address of your SaaS user that opens the document form builder.
  • external_id: Unique string to tag the opened document within the DocuSeal platform and to be able to reopen the form using this unique key.
  • documents_urls[]: An array with public and downloadable document URLs to be opened in the form builder. Pass empty array to allow users to upload their files.
  • template_id: ID of the existing template to open in the form builder - leave empty if `documents_urls[]` is specified. Templates can be created via the HTML API or PDF export API.

Ensure you never expose API_KEY on your client side, only generated and signed JWT should be passed to your front-end app.

const jwt = require('jsonwebtoken');

const API_KEY = process.env.DOCUSEAL_API_KEY // Obtain from DocuSeal Console

const token = jwt.sign({
  user_email: 'admin@company.com',
  integration_email: 'saas-user@company.com',
  external_id: 'TestForm123',
  name: 'Integration W-9 Test Form',
  document_urls: ['https://www.irs.gov/pub/irs-pdf/fw9.pdf'],
}, API_KEY);
2

Mount form builder component

Open your terminal or command prompt and navigate to your project directory. Then, run the following command to install the @docuseal/angular package

Once the installation is complete, you'll need to import the component in the relevant file where you intend to use DocuSeal. With the component imported, you can now use <docuseal-builder> within your Angular template wherever you want to integrate the DocuSeal document form builder functionality.

Trigger the API call to your backend endpoint to retrieve a JSON Web Token (JWT) generated on the previous step. The `ngOnInit` method triggers the API request upon component mount, fetching the JWT asynchronously.

Learn more:

Embed API Reference

Angular package on GitHub

Embedded Demo App

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { DocusealBuilderComponent } from '@docuseal/angular';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [DocusealBuilderComponent]
  template: `
    <div>
      <ng-container *ngIf="token; else loading">
        <docuseal-builder [token]="token"></docuseal-builder>
      </ng-container>
      <ng-template #loading>
        <p>Loading...</p>
      </ng-template>
    </div>
  `,
})
export class AppComponent implements OnInit {
  token: string | null = null;

  constructor(private http: HttpClient) {}

  ngOnInit() {
    this.fetchToken();
  }

  private fetchToken(): void {
    this.http.get<{ jwt: string }>('/your_backend/docuseal_builder/init').subscribe({
      next: (resp) => {
        // API should respond with JWT generated on your backend
        this.token = resp.jwt;
      }
    });
  }
}