mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Validate token and authenticate user before setting Speech state to FAILED
This commit is contained in:
parent
463f423cab
commit
cfdc236297
1 changed files with 12 additions and 14 deletions
|
|
@ -21,28 +21,25 @@ export function speechServiceRouter() {
|
|||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
body: req.body,
|
||||
})
|
||||
const token = req.query.token as string
|
||||
try {
|
||||
if (!(await getClaimsByToken(token))) {
|
||||
logger.info('Unauthorized request', { token })
|
||||
return res.status(200).send('UNAUTHORIZED')
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('Unauthorized request', { token, error })
|
||||
return res.status(200).send('UNAUTHORIZED')
|
||||
}
|
||||
|
||||
const { userId, speechId } = req.body as {
|
||||
userId: string
|
||||
speechId: string
|
||||
}
|
||||
if (!userId || !speechId) {
|
||||
speechId && (await setSpeechFailure(speechId))
|
||||
return res.status(200).send('Invalid data')
|
||||
}
|
||||
|
||||
const token = req.query.token as string
|
||||
try {
|
||||
if (!(await getClaimsByToken(token))) {
|
||||
logger.info('Unauthorized request', { token })
|
||||
await setSpeechFailure(speechId)
|
||||
return res.status(200).send('UNAUTHORIZED')
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('Unauthorized request', { token, error })
|
||||
await setSpeechFailure(speechId)
|
||||
return res.status(200).send('UNAUTHORIZED')
|
||||
}
|
||||
|
||||
logger.info(`Create article speech`, {
|
||||
body: {
|
||||
userId,
|
||||
|
|
@ -54,6 +51,7 @@ export function speechServiceRouter() {
|
|||
})
|
||||
const speech = await getRepository(Speech).findOneBy({
|
||||
id: speechId,
|
||||
user: { id: userId },
|
||||
})
|
||||
if (!speech) {
|
||||
return res.status(200).send('Speech not found')
|
||||
|
|
|
|||
Loading…
Reference in a new issue