getAuthUser becomes async.
This commit is contained in:
parent
07353bd327
commit
3658ee797a
7
server/@types/peertube.d.ts
vendored
7
server/@types/peertube.d.ts
vendored
@ -84,12 +84,15 @@ enum UserRole {
|
|||||||
USER = 2
|
USER = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MUserAccountUrl { // FIXME: this interface is not complete
|
interface MUserDefault { // FIXME: this interface is not complete
|
||||||
id?: string
|
id?: string
|
||||||
username: string
|
username: string
|
||||||
email: string
|
email: string
|
||||||
blocked: boolean
|
blocked: boolean
|
||||||
role: UserRole
|
role: UserRole
|
||||||
|
Account: {
|
||||||
|
name: string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface VideoBlacklistCreate {
|
interface VideoBlacklistCreate {
|
||||||
@ -128,7 +131,7 @@ interface PeerTubeHelpers {
|
|||||||
}
|
}
|
||||||
// Added in Peertube 3.2.0
|
// Added in Peertube 3.2.0
|
||||||
user?: {
|
user?: {
|
||||||
getAuthUser: (res: express.Response) => MUserAccountUrl | undefined
|
getAuthUser: (res: express.Response) => Promise<MUserDefault | undefined>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ function getBaseStaticRoute (): string {
|
|||||||
|
|
||||||
// Peertube <= 3.1.0 has no way to test that current user is admin
|
// Peertube <= 3.1.0 has no way to test that current user is admin
|
||||||
// Peertube >= 3.2.0 has getAuthUser helper
|
// Peertube >= 3.2.0 has getAuthUser helper
|
||||||
function isUserAdmin (options: RegisterServerOptions, res: Response): boolean {
|
async function isUserAdmin (options: RegisterServerOptions, res: Response): Promise<boolean> {
|
||||||
const user = getAuthUser(options, res)
|
const user = await getAuthUser(options, res)
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -40,7 +40,8 @@ function isUserAdmin (options: RegisterServerOptions, res: Response): boolean {
|
|||||||
// Peertube <= 3.1.0 has no way to get user informations.
|
// Peertube <= 3.1.0 has no way to get user informations.
|
||||||
// This is a hack.
|
// This is a hack.
|
||||||
// Peertube >= 3.2.0 has getAuthUser helper
|
// Peertube >= 3.2.0 has getAuthUser helper
|
||||||
function getAuthUser ({ peertubeHelpers }: RegisterServerOptions, res: Response): MUserAccountUrl | undefined {
|
async function getAuthUser (options: RegisterServerOptions, res: Response): Promise<MUserDefault | undefined> {
|
||||||
|
const peertubeHelpers = options.peertubeHelpers
|
||||||
if (peertubeHelpers.user?.getAuthUser) {
|
if (peertubeHelpers.user?.getAuthUser) {
|
||||||
return peertubeHelpers.user.getAuthUser(res)
|
return peertubeHelpers.user.getAuthUser(res)
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
|
|||||||
|
|
||||||
router.get('/auth', asyncMiddleware(
|
router.get('/auth', asyncMiddleware(
|
||||||
async (req: Request, res: Response, _next: NextFunction) => {
|
async (req: Request, res: Response, _next: NextFunction) => {
|
||||||
const user = getAuthUser(options, res)
|
const user = await getAuthUser(options, res)
|
||||||
if (!user) {
|
if (!user) {
|
||||||
res.sendStatus(403)
|
res.sendStatus(403)
|
||||||
return
|
return
|
||||||
|
@ -24,7 +24,7 @@ async function initSettingsRouter (options: RegisterServerOptions): Promise<Rout
|
|||||||
res.sendStatus(403)
|
res.sendStatus(403)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!isUserAdmin(options, res)) {
|
if (!await isUserAdmin(options, res)) {
|
||||||
res.sendStatus(403)
|
res.sendStatus(403)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user