How to use the @yarnpkg/plugin-npm.npmHttpUtils.AuthType function in @yarnpkg/plugin-npm

To help you get started, we’ve selected a few @yarnpkg/plugin-npm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yarnpkg / berry / packages / plugin-npm-cli / sources / commands / npm / login.ts View on Github external
}, async report => {
      const credentials = await getCredentials(prompt);
      const url = `/-/user/org.couchdb.user:${encodeURIComponent(credentials.name)}`;

      try {
        const response = await npmHttpUtils.put(url, credentials, {
          configuration,
          registry,
          json: true,
          authType: npmHttpUtils.AuthType.NO_AUTH,
        });

        // @ts-ignore
        await setAuthToken(registry, response.token, {configuration});

        return report.reportInfo(MessageName.UNNAMED, `Successfully logged in`);
      } catch (error) {
        return report.reportError(MessageName.AUTHENTICATION_INVALID, `Invalid Authentication`);
      }
    });
github yarnpkg / berry / packages / plugin-npm-cli / sources / commands / npm / whoami.ts View on Github external
}, async report => {
      try {
        const response = await npmHttpUtils.get(`/-/whoami`, {
          configuration,
          registry,
          authType: npmHttpUtils.AuthType.ALWAYS_AUTH,
          json: true,
        });

        report.reportInfo(MessageName.UNNAMED, response.username);
      } catch (err) {
        if (err.name !== `HTTPError`) {
          throw err;
        } else if (err.response.statusCode === 401 || err.response.statusCode === 403) {
          report.reportError(MessageName.AUTHENTICATION_INVALID, `Authentication failed - your credentials may have expired`);
        } else {
          report.reportError(MessageName.AUTHENTICATION_INVALID, err.toString());
        }
      }
    });