mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 07:17:04 +00:00
Updating type definitions for hapi-auth-basic >= 5.0.0.
This commit is contained in:
@@ -22,21 +22,22 @@ const users: {[index: string]: User} = {
|
||||
}
|
||||
};
|
||||
|
||||
const validate: Basic.ValidateFunc = function (request, username, password, callback) {
|
||||
const validate: Basic.Validate = async (request, username, password, h) => {
|
||||
|
||||
const user = users[username];
|
||||
if (!user) {
|
||||
return callback(null, false);
|
||||
return { isValid: false, credentials: null };
|
||||
}
|
||||
|
||||
Bcrypt.compare(password, user.password, (err, isValid) => {
|
||||
let isValid = await Bcrypt.compare(password, user.password)
|
||||
|
||||
callback(err, isValid, { id: user.id, name: user.name });
|
||||
});
|
||||
return { isValid, credentials: { id: user.id, name: user.name } };
|
||||
};
|
||||
|
||||
server.register(Basic, (err) => {
|
||||
server.register(Basic).then(() => {
|
||||
|
||||
server.auth.strategy('simple', 'basic', { validate });
|
||||
server.auth.default('simple');
|
||||
|
||||
server.auth.strategy('simple', 'basic', { validateFunc: validate });
|
||||
server.route({ method: 'GET', path: '/', config: { auth: 'simple' } });
|
||||
});
|
||||
|
||||
Vendored
+11
-5
@@ -1,18 +1,24 @@
|
||||
// Type definitions for hapi 4.2
|
||||
// Type definitions for hapi-bauth-basic 5.0.0
|
||||
// Project: https://github.com/hapijs/hapi-auth-basic
|
||||
// Definitions by: AJP <https://github.com/AJamesPhillips>
|
||||
// Rodrigo Saboya <https://github.com/saboya>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
import * as Hapi from 'hapi';
|
||||
|
||||
declare namespace Basic {
|
||||
interface ValidateFuncCallback {
|
||||
(err: Error | null, isValid: boolean, userCredentials?: any): void;
|
||||
interface ValidateCustomResponse {
|
||||
response: any,
|
||||
}
|
||||
|
||||
interface ValidateFunc {
|
||||
(request: Hapi.Request, username: string, password: string, callback: ValidateFuncCallback): void;
|
||||
interface ValidateResponse {
|
||||
isValid: boolean,
|
||||
credentials?: any,
|
||||
}
|
||||
|
||||
interface Validate {
|
||||
(request: Hapi.Request, username: string, password: string, h: object): Promise<ValidateResponse | ValidateCustomResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user