Skip to main content

Add Javascript SDK to your Front-end

First, install @membranehq/sdk NPM package:
npm install @membranehq/sdk
Then, initialize the SDK with an Authentication Token:
import { MembraneClient } from '@membranehq/sdk'

const membrane = new MembraneClient({
  // Test authentication token. You will need to replace it with the real one.
  token: '',
})
In this example we use the test token you can find on the Settings page of your workspace.
You will need to replace it with a real authentication token later (see Authentication).
To verify that everything works, let’s open our drop-in integration UI:
await membrane.open()
In the end your basic Vue.js setup may look like this:
<script setup lang="ts">
import { MembraneClient } from '@membranehq/sdk'

const token = await tokenResp.json()

const membrane = new MembraneClient({
  token,
})
</script>

<template>
  <div v-if="!token">Loading...</div>
  <div v-else>
    <button class="btn btn-sm btn-outline m-2" v-on:click="membrane.open">Configure Integrations</button>
  </div>
</template>

Dynamic Token

If it is more convenient for you to fetch token dynamically instead of providing static value, you can use fetchToken instead:
import { MembraneClient } from '@membranehq/sdk'

const membrane = new MembraneClient({
  // Test authentication token. You will need to replace it with the real one.
  async fetchToken() {
    return ''
  },
})
This option also automatically handles token expiration. If SDK was initialized long ago and token had time to expire, it will be automatically re-fetched before making new API requests.

SDK Reference

To see the full list of SDK methods check out the JavaScript API Reference.