Sitelet https://web.archive.org/web/20201016112639/https://github.com/verdaccio/verdaccio/issues/1924
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@types - AuthCallback: Incorrect definition #1924

Open
pusherman opened this issue Jun 17, 2020 · 1 comment
Open

@types - AuthCallback: Incorrect definition #1924

pusherman opened this issue Jun 17, 2020 · 1 comment
Assignees
Milestone

Comments

@pusherman
Copy link

@pusherman pusherman commented Jun 17, 2020

https://github.com/verdaccio/monorepo/blob/9.x/core/types/index.d.ts defines

type AuthAccessCallback = (error: string | null, access: boolean) => void;

interface IPluginAuth<T> extends IPlugin<T> {
  authenticate(user: string, password: string, cb: AuthCallback): void;
  adduser?(user: string, password: string, cb: AuthCallback): void;
  changePassword?(user: string, password: string, newPassword: string, cb: AuthCallback): void;
  allow_publish?(user: RemoteUser, pkg: T & PackageAccess, cb: AuthAccessCallback): void;
  allow_access?(user: RemoteUser, pkg: T & PackageAccess, cb: AuthAccessCallback): void;
  allow_unpublish?(user: RemoteUser, pkg: T & PackageAccess, cb: AuthAccessCallback): void;
  allow_publish?(user: RemoteUser, pkg: AllowAccess & PackageAccess, cb: AuthAccessCallback): void;
  allow_access?(user: RemoteUser, pkg: AllowAccess & PackageAccess, cb: AuthAccessCallback): void;
  allow_unpublish?(user: RemoteUser, pkg: AllowAccess & PackageAccess, cb: AuthAccessCallback): void;
  apiJWTmiddleware?(helpers: any): Function;
}

However, the server seems to be expecting an object when there is an error for the callback, not a string.

When I try to pass an error: string the server throws an error, it seems to be expecting an object. I have to pass null to prevent the server from throwing an error.

Example Code

public authenticate(username: string, password: string, cb: AuthCallback): void {

  // fetch the user and set validPassword

  return validPassword ? cb(null, fetchedUser.groups) : cb('user not found', false);
}

Output from server

npm ERR! Unexpected token u in JSON at position 0 while parsing near 'user not found'

@juanpicado juanpicado self-assigned this Jun 19, 2020
@juanpicado
Copy link
Member

@juanpicado juanpicado commented Jul 4, 2020

Hi @pusherman would you willing to PR a solution?

@juanpicado juanpicado transferred this issue from verdaccio/monorepo Aug 28, 2020
@juanpicado juanpicado added this to the 5.x.x milestone Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.