Vue + Vite
A guide to integrate the Capsule Modal (React-based) into your Vue application powered by Vite.
This guide shows you how to integrate the Capsule Modal—which is React-based—within a Vue application using
Vite. While mixing React with Vue isn’t always considered best practice, it is entirely possible by bridging to the
React modal via a connector. If you prefer to build your own custom UI, you can also use @usecapsule/web-sdk
directly.
Prerequisites
To use Capsule, you need an API key. This key authenticates your requests to Capsule services and is essential for integration.
Don’t have an API key yet? Request access to the Developer Portal to create API keys, manage billing, teams, and more.
Installing Dependencies
First, install both the Capsule React SDK and the React dependencies, since the modal relies on React under the hood:
Setting Up Polyfills
Like any React + Vite project that may rely on Node modules (crypto
, buffer
, stream
), you’ll likely need
polyfills:
Then, update your vite.config.js
or vite.config.ts
:
Setting Up the Capsule SDK
Now that you’ve installed the necessary dependencies, let’s set up the Capsule SDK in your Vue project. This involves creating a client instance and optionally configuring Next.js to transpile external modules if needed.
Creating a Capsule Client Instance
Just like in React apps, you need a Capsule client instance. You can keep it in a dedicated file (e.g.,
client/capsule.ts
):
Capsule offers two hosted environments: Environment.BETA
(alias Environment.DEVELOPMENT
) for
testing, and Environment.PROD
(alias Environment.PRODUCTION
) for live use. Select the
environment that matches your current development phase.
Building a Connector for the React Modal
To display the React-based Capsule Modal from within Vue, we’ll create a “connector” that mounts the React modal into a
DOM element. You can store this in a file such as capsule-modal-connector.tsx
:
This connector creates a React root within a given DOM element and renders the Capsule Modal into it. It also provides a few methods to open, close, and check the modal’s state.
Integrating in a Vue Component
Use Vue’s lifecycle hooks to create and destroy the modal connector. Below is a simplified example (index.vue
):
When you click the Open Capsule Modal button, the React-based Capsule Modal will appear within your Vue application.
Beta Testing Credentials
In the BETA
Environment, you can use any email ending in @test.usecapsule.com
(like dev@test.usecapsule.com) or US phone numbers (+1) in the format (area code)-555-xxxx
(like (425)-555-1234). Any OTP code will work for verification with these test credentials.
These credentials are for beta testing only. You can delete test users anytime in the beta developer console to free up user slots.
Customizing the Capsule Modal
All the usual customization props apply, just as in a React app:
Pass them through your connector’s props
object as needed.
If You Don’t Want to Use the React Modal
You can also build a custom UI using @usecapsule/web-sdk. This SDK gives you direct access to Capsule functionality (authentication, signing, etc.), letting you craft your own Vue components without bridging to React.
Examples
For an example of a fully working Vue + Vite integration, check out our starter templates or example repositories:
Next Steps
After integrating Capsule, you can explore other features and integrations to enhance your Capsule experience. Here are some resources to help you get started:
Ecosystems
Learn how to use Capsule with popular Web3 clients and wallet connectors. We’ll cover integration with key libraries for EVM, Solana, and Cosmos ecosystems.
If you’re ready to go live with your Capsule integration, make sure to review our go-live checklist:
Troubleshooting
Integration Support
If you’re experiencing issues that aren’t resolved by our troubleshooting resources, please contact our team for assistance. To help us resolve your issue quickly, please include the following information in your request:
1
A detailed description of the problem you’re encountering.
2
Any relevant error messages or logs.
3
Steps to reproduce the issue.
4
Details about your system or environment (e.g., device, operating system, software version).
Providing this information will enable our team to address your concerns more efficiently.
Was this page helpful?