set api key when setting the phone number to avoid race conditions later when fetching calls and messages

This commit is contained in:
m5r
2021-08-08 13:34:15 +08:00
parent 6ad516a99e
commit 0b34e861e0
3 changed files with 18 additions and 18 deletions

View File

@ -34,6 +34,16 @@ export default resolver.pipe(resolver.zod(Body), resolver.authorize(), async ({
});
context.session.$setPrivateData({ hasCompletedOnboarding: true });
const mainTwilioClient = twilio(organization.twilioAccountSid, organization.twilioAuthToken);
const apiKey = await mainTwilioClient.newKeys.create({ friendlyName: "Shellphone API key" });
await db.organization.update({
where: { id: organizationId },
data: {
twilioApiKey: apiKey.sid,
twilioApiSecret: apiKey.secret,
},
});
const phoneNumberId = phoneNumberSid;
await Promise.all([
fetchMessagesQueue.enqueue(