oauth + phone update

This commit is contained in:
Claeb101 2023-03-05 02:30:10 -05:00
parent 85c532ae33
commit aa798fcfab
3 changed files with 24 additions and 9 deletions

View File

@ -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
}
}

View File

@ -40,8 +40,6 @@ export const chat = async (callId) => {
});
}
console.log(messages);
const res = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: messages,

View File

@ -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: {