mirror of
https://github.com/arthur-pbty/portfolio2023.git
synced 2026-06-04 15:56:24 +02:00
70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
"use strict";
|
|
/*
|
|
* @adonisjs/auth
|
|
*
|
|
* (c) Harminder Virk <virk@adonisjs.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
/**
|
|
* Auth provider to register the auth binding
|
|
*/
|
|
class AuthProvider {
|
|
constructor(application) {
|
|
this.application = application;
|
|
}
|
|
/**
|
|
* Register auth binding
|
|
*/
|
|
register() {
|
|
this.application.container.singleton('Adonis/Addons/Auth', () => {
|
|
const authConfig = this.application.container
|
|
.resolveBinding('Adonis/Core/Config')
|
|
.get('auth', {});
|
|
const { AuthManager } = require('../src/AuthManager');
|
|
return new AuthManager(this.application, authConfig);
|
|
});
|
|
}
|
|
/**
|
|
* Sharing the auth object with HTTP context
|
|
*/
|
|
registerAuthWithHttpContext() {
|
|
this.application.container.withBindings(['Adonis/Core/HttpContext', 'Adonis/Addons/Auth'], (HttpContext, Auth) => {
|
|
HttpContext.getter('auth', function auth() {
|
|
return Auth.getAuthForRequest(this);
|
|
}, true);
|
|
});
|
|
}
|
|
/**
|
|
* Sharing auth with all the templates
|
|
*/
|
|
shareAuthWithViews() {
|
|
this.application.container.withBindings(['Adonis/Core/Server', 'Adonis/Core/View'], (Server) => {
|
|
Server.hooks.before(async (ctx) => {
|
|
ctx['view'].share({ auth: ctx.auth });
|
|
});
|
|
});
|
|
}
|
|
/**
|
|
* Register test bindings
|
|
*/
|
|
registerTestBindings() {
|
|
this.application.container.withBindings(['Japa/Preset/ApiRequest', 'Japa/Preset/ApiClient', 'Adonis/Addons/Auth'], (ApiRequest, ApiClient, Auth) => {
|
|
const { defineTestsBindings } = require('../src/Bindings/Tests');
|
|
return defineTestsBindings(ApiRequest, ApiClient, Auth);
|
|
});
|
|
}
|
|
/**
|
|
* Hook into boot to register auth macro
|
|
*/
|
|
async boot() {
|
|
this.registerAuthWithHttpContext();
|
|
this.shareAuthWithViews();
|
|
this.registerTestBindings();
|
|
}
|
|
}
|
|
exports.default = AuthProvider;
|
|
AuthProvider.needsApplication = true;
|