0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-27 22:59:51 -05:00

refactor: add types on auth files

This commit is contained in:
Juan Picado @jotadeveloper 2018-07-17 20:33:51 +02:00
parent 66118ad008
commit 9ade39a264
No known key found for this signature in database
GPG key ID: 18AC54485952D158
2 changed files with 14 additions and 10 deletions

View file

@ -1,8 +1,12 @@
// @flow
import {ErrorCode} from './utils';
import {API_ERROR} from './constants';
export function allow_action(action) {
return function(user, pkg, callback) {
import type {RemoteUser, Package, Callback} from '@verdaccio/types';
export function allow_action(action: string) {
return function(user: RemoteUser, pkg: Package, callback: Callback) {
const {name, groups} = user;
const hasPermission = pkg[action].some((group) => name === group || groups.includes(group));
@ -20,11 +24,11 @@ export function allow_action(action) {
export function getDefaultPlugins() {
return {
authenticate(user, password, cb) {
authenticate(user: string, password: string, cb: Callback) {
cb(ErrorCode.getForbidden(API_ERROR.BAD_USERNAME_PASSWORD));
},
add_user(user, password, cb) {
add_user(user: string, password: string, cb: Callback) {
return cb(ErrorCode.getConflict(API_ERROR.BAD_USERNAME_PASSWORD));
},

View file

@ -126,11 +126,11 @@ class Auth implements IAuth {
(function next() {
const plugin = plugins.shift();
if (typeof(plugin.allow_access) !== 'function') {
if (_.isFunction(plugin.allow_access) === false) {
return next();
}
plugin.allow_access(user, pkg, function(err, ok) {
plugin.allow_access(user, pkg, function(err, ok: boolean) {
if (err) {
return callback(err);
}
@ -155,11 +155,11 @@ class Auth implements IAuth {
(function next() {
const plugin = plugins.shift();
if (typeof(plugin.allow_publish) !== 'function') {
if (_.isFunction(plugin.allow_publish) === false) {
return next();
}
plugin.allow_publish(user, pkg, (err, ok) => {
plugin.allow_publish(user, pkg, (err, ok: boolean) => {
if (err) {
return callback(err);
}
@ -188,7 +188,8 @@ class Auth implements IAuth {
return _next();
};
if (req.remote_user != null && req.remote_user.name !== undefined) {
if (_.isUndefined(req.remote_user) === false
&& _.isUndefined(req.remote_user.name) === false) {
return next();
}
req.remote_user = buildAnonymousUser();
@ -204,7 +205,6 @@ class Auth implements IAuth {
}
const credentials = this._parseCredentials(parts);
if (!credentials) {
return next();
}