Integrating Finch with your frontend and backend can be daunting. Managing access tokens, handling null data, knowing which API endpoints to call when, etc. This sample application is meant to help you get started to see how an application can properly implement Finch. Start by running the application locally on your computer and then search through the code for any pages or components that you find interesting.
Since Finch requires having a frontend and a backend (for application security reasons), Next.js is perfect platform since it bundles a React client-side frontend with a server-side backend API running as serverless functions.
- Register for a Finch Sandbox Application.
- Configure the following
Redirect URL
for this application under the "Redirect URIs" section of the "Sandbox" page:http://localhost:3000/api/finch/callback
- Take note of the
Client ID
andClient Secret
. You'll need these values in the next step. You will need to regenerate the Client Secret the first time before using.
Create a .env.local
file under your root project directory (or copy our example file by running cp .env.local.example .env.local
in the terminal).
Define the necessary Finch configuration values as follows:
BASE_URL=http://localhost:3000
FINCH_API_URL=https://api.tryfinch.com
FINCH_SANDBOX_URL=https://api.tryfinch.com
FINCH_CLIENT_ID=
FINCH_CLIENT_SECRET=
NEXT_PUBLIC_FINCH_REDIRECT_URI=http://localhost:3000/api/finch/callback
NEXT_PUBLIC_BASE_URL=http://localhost:3000
NEXT_PUBLIC_FINCH_API_URL=https://api.tryfinch.com
NEXT_PUBLIC_FINCH_SANDBOX_URL=https://api.tryfinch.com
NEXT_PUBLIC_FINCH_CLIENT_ID=
NEXT_PUBLIC_FINCH_CLIENT_SECRET=
-
Start by installing the dependencies of this project:
npm install
oryarn install
. -
Then, run the development server:
npm run dev
oryarn dev
. -
Open http://localhost:3000 with your browser to see the result.
-
Create a new connection by either selecting
Redirect Flow
orEmbed Flow
.
You can start editing the app by modifying components/finch-connect.tsx
or components/navbar.tsx
or pages/api/finch
. The pages auto-update as you edit the files.
-
This app uses
node-json-db
package as a "stand-in" database to make it easy to store access tokens. Replace/util/database.ts
with your preference of database. -
This app uses
swr
package to fetch API requests. A global fetcher function is used which includes a progress bar when loading. Editable incomponents/layout.tsx
andpages/_app.tsx
. -
If you want to manually set the
current_connection
, overide the access token located in./database.json
(after running the application locally). -
Always try to check for null values when displaying data in a user interface
ex: (employee?.email)
The benefits of using Gitpod vs running locally is that this entire application can be built completely in a browser - no additional machine software dependencies required.
-
Copy our example configuration file by running
cp .env.local.example .env.local
in the terminal). -
Then, run the development server:
npm run dev
oryarn dev
-
Open http://localhost:3000 with your browser to see the result.