From 3cf00043b19e54d109c4809f48363b3efd3c339a Mon Sep 17 00:00:00 2001 From: nicolas Date: Mon, 14 Jun 2021 18:13:54 +0200 Subject: [PATCH] Persist new refresh token --- lib/videoClient.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/videoClient.ts b/lib/videoClient.ts index 0f6efcfc..e48ef404 100644 --- a/lib/videoClient.ts +++ b/lib/videoClient.ts @@ -1,3 +1,5 @@ +import prisma from "./prisma"; + function handleErrorsJson(response) { if (!response.ok) { response.json().then(console.log); @@ -31,7 +33,16 @@ const zoomAuth = (credential) => { }) }) .then(handleErrorsJson) - .then((responseBody) => { + .then(async (responseBody) => { + // Store new tokens in database. + await prisma.credential.update({ + where: { + id: credential.id + }, + data: { + key: responseBody + } + }); credential.key.access_token = responseBody.access_token; credential.key.expires_in = Math.round((+(new Date()) / 1000) + responseBody.expires_in); return credential.key.access_token;