Sessions and Endpoints
In e-signing applications, particularly in the browser, it is very common to need to track more than one session at a time:
- Differentiating between tasks. A user might be accessing their own organization's data (such as HR forms) in one browser tab, and open a new tab to sign a document sent by another user (a lease for a new apartment).
- Accessing multiple accounts. A developer might create two organizations, one for development work and one for their Production environment, and need to access both at the same time.
To support these use-cases the Verdocs JS/TS SDK requires endpoints to be explicitly identified. A helper class calledVerdocsEndpoint
tracks the current session, and additional instances may be created for new sessions. To simplify development for applications that do not require this functionality, a default instance is provided:
import {VerdocsEndpoint, getTemplates} from '@verdocs/js-sdk';
const templates = await getTemplates(VerdocsEndpoint.getDefault());
console.log('My templates', templates);
NextJS Considerations
With the introduction of the App Router in NextJS v13+, components default to running on the server ('use server';
). The Verdocs JS-SDK is isomorphic and can run in either environment, so it is compatible with both server and client components. However, NextJS does not provide a way for vanilla JS code to "transport" itself between environments - it only manages React components. This means user sessions will not be shared between server and client components by default.
If you use this library in NextJS, you must do one of the following:
- Ensure that all calls aare made only in one of the two environments, by applying
'use server';
or'use client';
to each component. - Provide a mechanism to transport user credentials from the server to the client, such as via an API call to obtain the user's access token and calling
VerdocsEndpoint.setToken(ACCESS_TOKEN)
on the client.Applications that do so should follow all industry best-practices for working with sensitive data, including encrypting communications between client and server, securely storing the token, etc.