From aa798fcfabd3df1c8bbbb6a8aa9f0bb171d7a802 Mon Sep 17 00:00:00 2001 From: Claeb101 Date: Sun, 5 Mar 2023 02:30:10 -0500 Subject: [PATCH] oauth + phone update --- src/authorize.js | 14 ++++++++++---- src/chat.js | 2 -- src/operator.js | 17 ++++++++++++++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/authorize.js b/src/authorize.js index 67ac7f3..e460489 100644 --- a/src/authorize.js +++ b/src/authorize.js @@ -8,11 +8,17 @@ export const authorize = async (req, res, admin=false) => { const auth = JSON.parse(req.cookies.auth) if(auth) authorization = `Bearer ${auth.access_token}` } - req.headers.authorization = authorization - - console.log(authorization) + const token = authorization.replace("Bearer ", "") + const webSession = await db.webSession.findUnique({ + where: { + token: token + }, + }) + + const authorized = webSession != null return { - authorized + authorized, + webSession } } \ No newline at end of file diff --git a/src/chat.js b/src/chat.js index 1f390fe..c9a5b40 100644 --- a/src/chat.js +++ b/src/chat.js @@ -40,8 +40,6 @@ export const chat = async (callId) => { }); } - console.log(messages); - const res = await openai.createChatCompletion({ model: "gpt-3.5-turbo", messages: messages, diff --git a/src/operator.js b/src/operator.js index b502763..5be15c2 100644 --- a/src/operator.js +++ b/src/operator.js @@ -21,10 +21,20 @@ app.post("/", async (req, res) => { }); app.post("/update", async (req, res) => { - console.log('hi') - const {authorized} = authorize(req, res) - return res.status(200).json({ + const {authorized, webSession} = await authorize(req, res) + if(!authorized) return res.status(401).send(null) + const operator = await db.operator.update({ + where: { + id: webSession.operatorId + }, + data: { + phoneNumber: req.body.phone + } + }) + + return res.status(200).json({ + operator }) }) @@ -53,6 +63,7 @@ app.post("/login", async (req, res) => { operatorId: operator.id } }); + if(!webSession){ webSession = await db.webSession.create({ data: {