This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+30
View File
@@ -0,0 +1,30 @@
/// <reference types="@adonisjs/application/build/adonis-typings/application" />
import { ApplicationContract } from '@ioc:Adonis/Core/Application';
/**
* Auth provider to register the auth binding
*/
export default class AuthProvider {
protected application: ApplicationContract;
constructor(application: ApplicationContract);
static needsApplication: boolean;
/**
* Register auth binding
*/
register(): void;
/**
* Sharing the auth object with HTTP context
*/
protected registerAuthWithHttpContext(): void;
/**
* Sharing auth with all the templates
*/
protected shareAuthWithViews(): void;
/**
* Register test bindings
*/
protected registerTestBindings(): void;
/**
* Hook into boot to register auth macro
*/
boot(): Promise<void>;
}
+69
View File
@@ -0,0 +1,69 @@
"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;