Skip to content

Commit

Permalink
fix: allow access to metadata before authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
dziraf committed Sep 20, 2022
1 parent 94dd2ef commit 4b8acd7
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,38 @@ export class Plugin extends BasePlugin<PluginOptions> {
this.protectRoutes()
}

private buildMetadataRoute(routes: AdminRoute[]) {
const route = routes.find((r) => r.action === 'metadata')
if (route) {
const expressPath = convertToExpressPath(route.path)
const handler = this.getRouteHandler(route)

if (route.method === 'GET') {
this.router.get(expressPath, handler)
}
}
}

public buildRoutes(): void {
const { routes } = AdminRouter

this.router.use(formidableMiddleware(this.options.formidableOptions ?? {}))

this.buildMetadataRoute(routes)
this.buildAuthenticationRoutes()

routes.forEach((route) => {
const expressPath = convertToExpressPath(route.path)
const handler = this.getRouteHandler(route)
if (route.action !== 'metadata') {
const expressPath = convertToExpressPath(route.path)
const handler = this.getRouteHandler(route)

if (route.method === 'GET') {
this.router.get(expressPath, handler)
}
if (route.method === 'GET') {
this.router.get(expressPath, handler)
}

if (route.method === 'POST') {
this.router.post(expressPath, handler)
if (route.method === 'POST') {
this.router.post(expressPath, handler)
}
}
})
}
Expand Down

0 comments on commit 4b8acd7

Please sign in to comment.