<!doctype html>

<head>
  <title>authentication • parametric-svg.surge.sh</title>
</head>

<body>
  <div id="oops" style="font-family: sans-serif"></div>

  <script>
    const oops = document.querySelector('#oops');
    const fail = () => {
      oops.innerHTML = (
        '<p>' +
          'Yikes! Something went wrong when authenticating you at github. ' +
          '<a href="javascript:window.close()">Try again</a> – and if that ' +
          'doesn’t work, <a href="https://github.com/parametric-svg/' +
          'parametric-svg.surge.sh/issues">let us know in an issue</a>.' +
        '</p>'
      );
    };

    const codeMatch = /[?&]code=(.+?)(?:$|&)/.exec(location.search);
    if (!codeMatch) fail();
    const code = codeMatch[1];

    fetch(`http://parametric-svg-auth.herokuapp.com/authenticate/${code}`).then(
      r => r.json()
    ).then((data) => {
      window.opener.postMessage(data.token, 'http://0.0.0.0:9229');
      window.close();
    });
  </script>
</body>

<!doctype html>

<head>
  <title>authentication • parametric-svg.surge.sh</title>
</head>

<body>
  <div id="display" style="font-family: sans-serif">Waiting for authentication. Make sure you don’t close this window – we’ll get you back to the app as soon as possible.</div>

  <script>
    const display = document.querySelector('#display');
    const fail = () => {
      display.innerHTML = (
        '<p>' +
          'Yikes! Something went wrong when authenticating you at github. ' +
          '<a href="javascript:window.close()">Try again</a> – and if that ' +
          'doesn’t work, <a href="https://github.com/parametric-svg/' +
          'parametric-svg.surge.sh/issues">let us know in an issue</a>.' +
        '</p>'
      );
    };

    const codeMatch = /[?&]code=(.+?)(?:$|&)/.exec(location.search);
    if (!codeMatch) fail();
    const code = codeMatch[1];

    fetch(`http://parametric-svg-auth.herokuapp.com/authenticate/${code}`).then(
      r => r.json()
    ).then((data) => {
      window.opener.postMessage(data.token, 'http://0.0.0.0:9229');
      window.close();
    });
  </script>
</body>

Add a barebones auth message
Add a barebones auth message
