mirror of
https://github.com/vitalityAI/therapist.git
synced 2025-04-08 05:40:17 -04:00
oauth + phone update
This commit is contained in:
parent
85c532ae33
commit
aa798fcfab
|
@ -8,11 +8,17 @@ export const authorize = async (req, res, admin=false) => {
|
||||||
const auth = JSON.parse(req.cookies.auth)
|
const auth = JSON.parse(req.cookies.auth)
|
||||||
if(auth) authorization = `Bearer ${auth.access_token}`
|
if(auth) authorization = `Bearer ${auth.access_token}`
|
||||||
}
|
}
|
||||||
req.headers.authorization = authorization
|
const token = authorization.replace("Bearer ", "")
|
||||||
|
const webSession = await db.webSession.findUnique({
|
||||||
console.log(authorization)
|
where: {
|
||||||
|
token: token
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const authorized = webSession != null
|
||||||
|
|
||||||
return {
|
return {
|
||||||
authorized
|
authorized,
|
||||||
|
webSession
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -40,8 +40,6 @@ export const chat = async (callId) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(messages);
|
|
||||||
|
|
||||||
const res = await openai.createChatCompletion({
|
const res = await openai.createChatCompletion({
|
||||||
model: "gpt-3.5-turbo",
|
model: "gpt-3.5-turbo",
|
||||||
messages: messages,
|
messages: messages,
|
||||||
|
|
|
@ -21,10 +21,20 @@ app.post("/", async (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/update", async (req, res) => {
|
app.post("/update", async (req, res) => {
|
||||||
console.log('hi')
|
const {authorized, webSession} = await authorize(req, res)
|
||||||
const {authorized} = authorize(req, res)
|
if(!authorized) return res.status(401).send(null)
|
||||||
return res.status(200).json({
|
|
||||||
|
|
||||||
|
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
|
operatorId: operator.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(!webSession){
|
if(!webSession){
|
||||||
webSession = await db.webSession.create({
|
webSession = await db.webSession.create({
|
||||||
data: {
|
data: {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user