@braustin-holdings/homebase-node-sdk
v0.0.2343
Published
A node SDK for interacting with braustin-holdings/homebase.
Downloads
76
Keywords
Readme
homebase-node-sdk
A node SDK for interacting with braustin-holdings/homebase. Provides an authenticated for the Homebase React Client.
Installation
npm i @braustin-holdings/homebase-node-sdk
Usage
Instantiate a new HomeBaseSDK object by passing it your app's clientId
and clientSecret
.
const HomeBaseSDK = require('@braustin-holdings/homebase-node-sdk')
const hb = new HomeBaseSDK('CLIENT_ID_HERE', 'CLIENT_SECRET_HERE')
Authentication with Homebase
There are two ways of obtaining a JSONwebtoken to gain access to the Homebase data. Choose whichever is most convenient for your app.
The getAuthToken method
For use in your controllers or scripts.
const tokenData = await hb.getAuthToken()
console.log(tokenData) // { token: '39fp...', graphqlUrl: 'https://homebase-api.herokuapp.com' }
As an Express middleware
If you're using express and the HomeBase React Client, you can easily obtain the token by including this middlware. NOTE you will want this to be one of the earlier middleware in the chain.
The Homebase React Client looks for the url used in the middelware.
const app = express()
app.use(hb.middleware.getAuthToken) // res.json({ token: '39fp...', graphqlUrl: 'https://homebase-api.herokuapp.com' })