This document provides instructions for setting up the Plaid integration for the Wealth Management Dashboard application. The integration allows users to connect their financial accounts securely using Plaid's API.
- Go to Plaid's Developer Dashboard and create an account
- Once logged in, create a new team if needed
- Navigate to the API keys section to obtain your Client ID and Secret keys
Create a .env file in the root of your project (or copy from .env.example) and add the following variables:
VITE_PLAID_CLIENT_ID=your_plaid_client_id
VITE_PLAID_SECRET=your_plaid_secret
VITE_PLAID_ENV=sandbox
For development, use the Sandbox environment. For production, change to development or production.
- Create a Supabase project if you haven't already
- Run the migration script in
supabase/migrations/20240601000000_create_plaid_tables.sqlto create the necessary tables - Add the following environment variables to your
.envfile:
VITE_SUPABASE_URL=your_supabase_url
VITE_SUPABASE_ANON_KEY=your_supabase_anon_key
The Plaid integration uses Supabase Edge Functions to securely handle API calls to Plaid. Deploy these functions using the Supabase CLI:
supabase functions deploy plaid-link-token
supabase functions deploy plaid-exchange-token
supabase functions deploy plaid-get-accounts
supabase functions deploy plaid-get-transactionsMake sure to set the environment variables in your Supabase project:
supabase secrets set PLAID_CLIENT_ID=your_plaid_client_id
supabase secrets set PLAID_SECRET=your_plaid_secret-
In Sandbox mode, you can use Plaid's test credentials:
- Username:
user_good - Password:
pass_good - Or any of the other test credentials
- Username:
-
For testing specific account types or error scenarios, refer to Plaid's Sandbox documentation
The Plaid integration consists of the following components:
-
Frontend Components:
PlaidLinkButton.tsx: Renders the Plaid Link button and handles the Plaid Link flowConnectAccountSection.tsx: Displays connected accounts and provides the interface for connecting new accounts
-
Context and Hooks:
PlaidContext.tsx: Provides global state for Plaid-related datausePlaidAPI.ts: Custom hook for interacting with the Plaid API
-
Backend (Supabase Edge Functions):
plaid-link-token: Creates a link token for initializing Plaid Linkplaid-exchange-token: Exchanges a public token for an access token and retrieves account informationplaid-get-accounts: Retrieves account information for a userplaid-get-transactions: Retrieves transaction data for a user's accounts
-
Database (Supabase):
plaid_items: Stores information about connected Plaid items (institutions)plaid_accounts: Stores information about individual accountsplaid_transactions: Stores transaction data
- Access tokens are never exposed to the frontend; they are stored securely in the database
- All API calls to Plaid are made through Supabase Edge Functions, which run in a secure environment
- Row-level security policies ensure that users can only access their own data
- If you encounter CORS issues, make sure your Supabase project allows requests from your application's domain
- For Plaid Link errors, check the browser console for detailed error messages
- If transactions aren't showing up, ensure that the date range for the transaction request is appropriate