Sitelet https://web.archive.org/web/20201125092352/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 · 3 comments
Open

@types - AuthCallback: Incorrect definition #1924

pusherman opened this issue Jun 17, 2020 · 3 comments
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
@dnafication
Copy link

@dnafication dnafication commented Oct 24, 2020

I checked this in https://github.com/verdaccio/verdaccio/tree/5.x and found to be fixed? Is there any work left on this? Or need to do replicate it in master?

Code in 5.x

type AuthError = HttpError & { code: number };
  type AuthAccessCallback = (error: AuthError | null, access: boolean) => void;
  type AuthCallback = (error: AuthError | null, groups: string[] | false) => 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;
@juanpicado
Copy link
Member

@juanpicado juanpicado commented Nov 12, 2020

@dnafication there is no progress on this yet, I decided to move first all plugins and modules to 5.x so change types is way easier, that step was already done. So the next step would be this one.

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
3 participants
You can’t perform that action at this time.