Skip to content

Commit fc46396

Browse files
committed
refactor: make ensureAuthenticated async
1 parent e493aa1 commit fc46396

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/node/routes/domainProxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ router.all("*", async (req, res, next) => {
7474

7575
export const wsRouter = WsRouter()
7676

77-
wsRouter.ws("*", (req, _, next) => {
77+
wsRouter.ws("*", async (req, _, next) => {
7878
const port = maybeProxy(req)
7979
if (!port) {
8080
return next()
8181
}
8282

8383
// Must be authenticated to use the proxy.
84-
ensureAuthenticated(req)
84+
await ensureAuthenticated(req)
8585

8686
proxy.ws(req, req.ws, req.head, {
8787
ignorePath: true,

src/node/routes/pathProxy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ export function proxy(
4545
})
4646
}
4747

48-
export function wsProxy(
48+
export async function wsProxy(
4949
req: pluginapi.WebsocketRequest,
5050
opts?: {
5151
passthroughPath?: boolean
5252
},
53-
): void {
54-
ensureAuthenticated(req)
53+
): Promise<void> {
54+
await ensureAuthenticated(req)
5555
_proxy.ws(req, req.ws, req.head, {
5656
ignorePath: true,
5757
target: getProxyTarget(req, opts?.passthroughPath),

src/node/routes/static.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ router.get("/(:commit)(/*)?", async (req, res) => {
1818
// Used by VS Code to load extensions into the web worker.
1919
const tar = getFirstString(req.query.tar)
2020
if (tar) {
21-
ensureAuthenticated(req)
21+
await ensureAuthenticated(req)
2222
let stream: Readable = tarFs.pack(pathToFsPath(tar))
2323
if (req.headers["accept-encoding"] && req.headers["accept-encoding"].includes("gzip")) {
2424
logger.debug("gzipping tar", field("path", tar))

typings/pluginapi.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ export const proxy: ProxyServer
145145
/**
146146
* Middleware to ensure the user is authenticated. Throws if they are not.
147147
*/
148-
export function ensureAuthenticated(req: express.Request, res?: express.Response, next?: express.NextFunction): void
148+
export function ensureAuthenticated(req: express.Request, res?: express.Response, next?: express.NextFunction): Promise<void>
149149

150150
/**
151151
* Returns true if the user is authenticated.
152152
*/
153-
export function authenticated(req: express.Request): boolean
153+
export function authenticated(req: express.Request): Promise<void>
154154

155155
/**
156156
* Replace variables in HTML: TO, BASE, CS_STATIC_BASE, and OPTIONS.

0 commit comments

Comments
 (0)