UNPKG

1.62 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../../src/middleware/initialize_auth_middleware.ts"],"sourcesContent":["/// <reference types=\"@adonisjs/core/providers/edge_provider\" />\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { NextFn } from '@adonisjs/core/types/http'\n\nimport type { Authenticator } from '../authenticator.js'\nimport type { Authenticators, GuardFactory } from '../types.js'\n\n/**\n * The \"InitializeAuthMiddleware\" is used to create a request\n * specific authenticator instance for every HTTP request.\n *\n * This middleware does not protect routes from unauthenticated\n * users. Please use the \"auth\" middleware for that.\n */\nexport default class InitializeAuthMiddleware {\n async handle(ctx: HttpContext, next: NextFn) {\n const auth = await ctx.containerResolver.make('auth.manager')\n\n /**\n * Initialize the authenticator for the current HTTP\n * request\n */\n ctx.auth = auth.createAuthenticator(ctx)\n\n /**\n * Sharing authenticator with templates\n */\n if ('view' in ctx) {\n ctx.view.share({ auth: ctx.auth })\n }\n\n return next()\n }\n}\n\ndeclare module '@adonisjs/core/http' {\n export interface HttpContext {\n auth: Authenticator<\n Authenticators extends Record<string, GuardFactory> ? Authenticators : never\n >\n }\n}\n"],"mappings":";;;AAeA,IAAqB,2BAArB,MAA8C;AAAA,EAC5C,MAAM,OAAO,KAAkB,MAAc;AAC3C,UAAM,OAAO,MAAM,IAAI,kBAAkB,KAAK,cAAc;AAM5D,QAAI,OAAO,KAAK,oBAAoB,GAAG;AAKvC,QAAI,UAAU,KAAK;AACjB,UAAI,KAAK,MAAM,EAAE,MAAM,IAAI,KAAK,CAAC;AAAA,IACnC;AAEA,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
\No newline at end of file