async function login() {
  const tokenFromStore = await (0, _manageToken.getToken)();

  if (tokenFromStore) {
    _reporter.default.info(`You are already logged in!`);

    return;
  }

  const webUrl = `https://gatsbyjs.com`;

  _reporter.default.info(`Logging into your Gatsby Cloud account...`); // Create "ticket" for auth (like an expiring session)


  const ticketId = await createTicket(); // Open browser for authentication

  const authUrl = `${webUrl}/dashboard/login?authType=EXTERNAL_AUTH&ticketId=${ticketId}&noredirect=1`;
  await handleOpenBrowser(authUrl); // Poll until the ticket has been verified, and should have the token attached

  function pollForTicket() {
    return new Promise(function (resolve) {
      // eslint-disable-next-line consistent-return
      async function verify() {
        const ticket = await getTicket(ticketId);
        const timeoutId = setTimeout(verify, 3000);

        if (ticket.verified) {
          clearTimeout(timeoutId);
          return resolve(ticket);
        }
      }

      verify();
    });
  }

  console.log(``);

  _reporter.default.info(`Waiting for login from Gatsby Cloud...`);

  const ticket = await pollForTicket();

  if (ticket !== null && ticket !== void 0 && ticket.token && ticket !== null && ticket !== void 0 && ticket.expiration) {
    await (0, _manageToken.setToken)(ticket.token, ticket.expiration);
  }

  _reporter.default.info(`You have been logged in!`);
}
/**
 * Main function that logs in to Gatsby Cloud using Gatsby Cloud's authentication service.
 */
Main function that logs in to Gatsby Cloud using Gatsby Cloud's authentication service.
Main function that logs in to Gatsby Cloud using Gatsby Cloud ' s authentication service .
async function login() {
  const tokenFromStore = await (0, _manageToken.getToken)();
  if (tokenFromStore) {
    _reporter.default.info(`You are already logged in!`);
    return;
  }
  const webUrl = `https://gatsbyjs.com`;
  _reporter.default.info(`Logging into your Gatsby Cloud account...`); 
  const ticketId = await createTicket(); 
  const authUrl = `${webUrl}/dashboard/login?authType=EXTERNAL_AUTH&ticketId=${ticketId}&noredirect=1`;
  await handleOpenBrowser(authUrl); 
  function pollForTicket() {
    return new Promise(function (resolve) {
      async function verify() {
        const ticket = await getTicket(ticketId);
        const timeoutId = setTimeout(verify, 3000);
        if (ticket.verified) {
          clearTimeout(timeoutId);
          return resolve(ticket);
        }
      }
      verify();
    });
  }
  console.log(``);
  _reporter.default.info(`Waiting for login from Gatsby Cloud...`);
  const ticket = await pollForTicket();
  if (ticket !== null && ticket !== void 0 && ticket.token && ticket !== null && ticket !== void 0 && ticket.expiration) {
    await (0, _manageToken.setToken)(ticket.token, ticket.expiration);
  }
  _reporter.default.info(`You have been logged in!`);
}
async function login ( ) { const tokenFromStore = await ( 0 , _manageToken . getToken ) ( ) ; if ( tokenFromStore ) { _reporter . default . info ( ` ` ) ; return ; } const webUrl = ` ` ; _reporter . default . info ( ` ` ) ; const ticketId = await createTicket ( ) ; const authUrl = ` ${ webUrl } ${ ticketId } ` ; await handleOpenBrowser ( authUrl ) ; function pollForTicket ( ) { return new Promise ( function ( resolve ) { async function verify ( ) { const ticket = await getTicket ( ticketId ) ; const timeoutId = setTimeout ( verify , 3000 ) ; if ( ticket . verified ) { clearTimeout ( timeoutId ) ; return resolve ( ticket ) ; } } verify ( ) ; } ) ; } console . log ( ` ` ) ; _reporter . default . info ( ` ` ) ; const ticket = await pollForTicket ( ) ; if ( ticket !== null && ticket !== void 0 && ticket . token && ticket !== null && ticket !== void 0 && ticket . expiration ) { await ( 0 , _manageToken . setToken ) ( ticket . token , ticket . expiration ) ; } _reporter . default . info ( ` ` ) ; }
Main function that logs in to Gatsby Cloud using Gatsby Cloud's authentication service.
Main function that logs in to Gatsby Cloud using Gatsby Cloud ' s authentication service .
// Create "ticket" for auth (like an expiring session) // Open browser for authentication // Poll until the ticket has been verified, and should have the token attached // eslint-disable-next-line consistent-return