Reorganize app workspaces and align Admin architecture
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { policies } from '#policies/main'
|
||||
import * as abilities from '#abilities/main'
|
||||
|
||||
import { Bouncer } from '@adonisjs/bouncer'
|
||||
import type { HttpContext } from '@adonisjs/core/http'
|
||||
import type { NextFn } from '@adonisjs/core/types/http'
|
||||
|
||||
/**
|
||||
* Init bouncer middleware is used to create a bouncer instance
|
||||
* during an HTTP request
|
||||
*/
|
||||
export default class InitializeBouncerMiddleware {
|
||||
async handle(ctx: HttpContext, next: NextFn) {
|
||||
/**
|
||||
* Create bouncer instance for the ongoing HTTP request.
|
||||
* We will pull the user from the HTTP context.
|
||||
*/
|
||||
ctx.bouncer = new Bouncer(
|
||||
() => ctx.auth.user || null,
|
||||
abilities,
|
||||
policies
|
||||
).setContainerResolver(ctx.containerResolver)
|
||||
|
||||
/**
|
||||
* Share bouncer helpers with Edge templates.
|
||||
*/
|
||||
// if ('view' in ctx) {
|
||||
// ctx.view?.share(ctx.bouncer.edgeHelpers)
|
||||
// }
|
||||
|
||||
return next()
|
||||
}
|
||||
}
|
||||
|
||||
declare module '@adonisjs/core/http' {
|
||||
export interface HttpContext {
|
||||
bouncer: Bouncer<
|
||||
Exclude<HttpContext['auth']['user'], undefined>,
|
||||
typeof abilities,
|
||||
typeof policies
|
||||
>
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user