diff --git a/server/@types/peertube.d.ts b/server/@types/peertube.d.ts index 66fb7608..8a128bcd 100644 --- a/server/@types/peertube.d.ts +++ b/server/@types/peertube.d.ts @@ -84,12 +84,15 @@ enum UserRole { USER = 2 } -interface MUserAccountUrl { // FIXME: this interface is not complete +interface MUserDefault { // FIXME: this interface is not complete id?: string username: string email: string blocked: boolean role: UserRole + Account: { + name: string + } } interface VideoBlacklistCreate { @@ -128,7 +131,7 @@ interface PeerTubeHelpers { } // Added in Peertube 3.2.0 user?: { - getAuthUser: (res: express.Response) => MUserAccountUrl | undefined + getAuthUser: (res: express.Response) => Promise } } diff --git a/server/lib/helpers.ts b/server/lib/helpers.ts index f19f8dfb..14c63186 100644 --- a/server/lib/helpers.ts +++ b/server/lib/helpers.ts @@ -23,8 +23,8 @@ function getBaseStaticRoute (): string { // Peertube <= 3.1.0 has no way to test that current user is admin // Peertube >= 3.2.0 has getAuthUser helper -function isUserAdmin (options: RegisterServerOptions, res: Response): boolean { - const user = getAuthUser(options, res) +async function isUserAdmin (options: RegisterServerOptions, res: Response): Promise { + const user = await getAuthUser(options, res) if (!user) { return false } @@ -40,7 +40,8 @@ function isUserAdmin (options: RegisterServerOptions, res: Response): boolean { // Peertube <= 3.1.0 has no way to get user informations. // This is a hack. // Peertube >= 3.2.0 has getAuthUser helper -function getAuthUser ({ peertubeHelpers }: RegisterServerOptions, res: Response): MUserAccountUrl | undefined { +async function getAuthUser (options: RegisterServerOptions, res: Response): Promise { + const peertubeHelpers = options.peertubeHelpers if (peertubeHelpers.user?.getAuthUser) { return peertubeHelpers.user.getAuthUser(res) } diff --git a/server/lib/routers/api.ts b/server/lib/routers/api.ts index 7826575e..4cbd5b99 100644 --- a/server/lib/routers/api.ts +++ b/server/lib/routers/api.ts @@ -89,7 +89,7 @@ async function initApiRouter (options: RegisterServerOptions): Promise { router.get('/auth', asyncMiddleware( async (req: Request, res: Response, _next: NextFunction) => { - const user = getAuthUser(options, res) + const user = await getAuthUser(options, res) if (!user) { res.sendStatus(403) return diff --git a/server/lib/routers/settings.ts b/server/lib/routers/settings.ts index c5b5a903..2d482349 100644 --- a/server/lib/routers/settings.ts +++ b/server/lib/routers/settings.ts @@ -24,7 +24,7 @@ async function initSettingsRouter (options: RegisterServerOptions): Promise