Shun Miyazawa 10 месяцев назад
Родитель
Сommit
89371aa5f2

+ 1 - 1
apps/app/src/server/crowi/index.js

@@ -62,7 +62,7 @@ class Crowi {
 
   /**
    * For retrieving other packages
-   * @type {(req: import('express').Request, res: import('express').Response, next: import('express').NextFunction) => Promise<void>}
+   * @type {import('~/server/middlewares/access-token-parser').AccessTokenParser}
    */
   accessTokenParser;
 

+ 6 - 4
apps/app/src/server/middlewares/access-token-parser/index.ts

@@ -1,13 +1,15 @@
-import type { NextFunction, Response } from 'express';
-
 import type { Scope } from '@growi/core/dist/interfaces';
+import type { NextFunction, Response } from 'express';
 
 import { parserForAccessToken } from './access-token';
 import { parserForApiToken } from './api-token';
 import type { AccessTokenParserReq } from './interfaces';
 
-export const accessTokenParser = (scopes?: Scope[], opts?: {acceptLegacy: boolean}) => {
-  return async(req: AccessTokenParserReq, res: Response, next: NextFunction): Promise<void> => {
+export type AccessTokenParser = (scopes?: Scope[], opts?: {acceptLegacy: boolean})
+  => (req: AccessTokenParserReq, res: Response, next: NextFunction) => Promise<void>
+
+export const accessTokenParser: AccessTokenParser = (scopes, opts) => {
+  return async(req, res, next): Promise<void> => {
     // TODO: comply HTTP header of RFC6750 / Authorization: Bearer
     if (scopes == null || scopes.length === 0) {
       return next();