A node SDK for interacting with braustin-holdings/homebase. Provides an authenticated for the Homebase React Client.
npm i @braustin-holdings/homebase-node-sdk
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')
There are two ways of obtaining a JSONwebtoken to gain access to the Homebase data. Choose whichever is most convenient for your app.
For use in your controllers or scripts.
const tokenData = await hb.getAuthToken()
console.log(tokenData) // { token: '39fp...', graphqlUrl: 'https://homebase-api.herokuapp.com' }
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' })