mirror of
https://github.com/sasjs/server.git
synced 2026-01-07 06:30:06 +00:00
chore: swagger authentication added
This commit is contained in:
@@ -8,7 +8,8 @@ import {
|
|||||||
Patch,
|
Patch,
|
||||||
Delete,
|
Delete,
|
||||||
Body,
|
Body,
|
||||||
Hidden
|
Hidden,
|
||||||
|
Security
|
||||||
} from 'tsoa'
|
} from 'tsoa'
|
||||||
import bcrypt from 'bcryptjs'
|
import bcrypt from 'bcryptjs'
|
||||||
|
|
||||||
@@ -28,7 +29,8 @@ interface userDetailsResponse {
|
|||||||
isAdmin: boolean
|
isAdmin: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@Route('user')
|
@Security('bearerAuth')
|
||||||
|
@Route('SASjsApi/user')
|
||||||
export default class UserController {
|
export default class UserController {
|
||||||
/**
|
/**
|
||||||
* Get list of all users (username, displayname). All users can request this.
|
* Get list of all users (username, displayname). All users can request this.
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
export const verifyAdminIfNeeded = (req: any, res: any, next: any) => {
|
export const verifyAdminIfNeeded = (req: any, res: any, next: any) => {
|
||||||
const { user } = req
|
const { user } = req
|
||||||
const { userId } = req.params
|
const userId = parseInt(req.params.userId)
|
||||||
|
|
||||||
if (!user.isAdmin && user.id !== userId) {
|
if (!user.isAdmin && user.userId !== userId) {
|
||||||
return res.status(401).send('Admin account required')
|
return res.status(401).send('Admin account required')
|
||||||
}
|
}
|
||||||
next()
|
next()
|
||||||
|
|||||||
@@ -3,6 +3,13 @@
|
|||||||
"noImplicitAdditionalProperties": "throw-on-extras",
|
"noImplicitAdditionalProperties": "throw-on-extras",
|
||||||
"spec": {
|
"spec": {
|
||||||
"outputDirectory": "public",
|
"outputDirectory": "public",
|
||||||
|
"securityDefinitions": {
|
||||||
|
"bearerAuth": {
|
||||||
|
"type": "http",
|
||||||
|
"scheme": "bearer",
|
||||||
|
"bearerFormat": "JWT"
|
||||||
|
}
|
||||||
|
},
|
||||||
"specVersion": 3
|
"specVersion": 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user