1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 |
|
12 |
|
13 |
|
14 | class AuthProvider {
|
15 | constructor(application) {
|
16 | this.application = application;
|
17 | }
|
18 | |
19 |
|
20 |
|
21 | register() {
|
22 | this.application.container.singleton('Adonis/Addons/Auth', () => {
|
23 | const authConfig = this.application.container
|
24 | .resolveBinding('Adonis/Core/Config')
|
25 | .get('auth', {});
|
26 | const { AuthManager } = require('../src/AuthManager');
|
27 | return new AuthManager(this.application, authConfig);
|
28 | });
|
29 | }
|
30 | |
31 |
|
32 |
|
33 | async boot() {
|
34 | this.application.container.withBindings(['Adonis/Core/HttpContext', 'Adonis/Addons/Auth'], (HttpContext, Auth) => {
|
35 | HttpContext.getter('auth', function auth() {
|
36 | return Auth.getAuthForRequest(this);
|
37 | }, true);
|
38 | });
|
39 | this.application.container.withBindings(['Adonis/Core/Server', 'Adonis/Core/View'], (Server) => {
|
40 | Server.hooks.before(async (ctx) => {
|
41 | ctx['view'].share({ auth: ctx.auth });
|
42 | });
|
43 | });
|
44 | }
|
45 | }
|
46 | exports.default = AuthProvider;
|
47 | AuthProvider.needsApplication = true;
|