nayelyz
(SmartThings Developer Support)
December 1, 2020, 7:50pm
6
DynamoDB is used only for the contextStore .
You can use any kind of persistent storage you want and save the object with the needed information to pass it to the withContext function of the SDK.
If you had the values in an object called localStore, then you would have to send this:
const ctx = await apiApp.withContext({
installedAppId: localStore.installedAppId,
locationId: localStore.locationId,
authToken: localStore.authToken,
refreshToken: localStore.refreshToken})
Or, as in this example, you could save those values in a server session:
const ctx = await smartApp.withContext(req.session.smartThings)
await ctx.api.installedApps.delete()
req.session.destroy(() => {
res.redirect('/')
})
});
/* Executes a scene */
server.post('/scenes/:sceneId', function (req, res) {
smartApp.withContext(req.session.smartThings).then(ctx => {
ctx.api.scenes.execute(req.params.sceneId).then(result => {
res.send(result)
})
})
});
/* Handles OAuth redirect */
server.get('/oauth/callback', async (req, res) => {
// Exchange the code for the auth token. Returns an API context that can be used for subsequent calls
const ctx = await smartApp.handleOAuthCallback(req)
2 Likes