cmd/tailscale/cli: skip new tab on web login

It doesn't work properly.

Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
This commit is contained in:
David Crawshaw 2021-04-02 12:03:25 -04:00
parent 2b5b36ec63
commit 182683492c

View File

@ -11,7 +11,7 @@
</head>
<body class="py-14">
<main class="container max-w-lg mx-auto py-6 px-8 bg-white rounded-md shadow-2xl" style="width: 95%">
<main class="container max-w-lg mx-auto py-6 px-8 bg-white rounded-md shadow-2xl" style="width: 95%">
<header class="flex justify-between items-center min-width-0 py-2 mb-8">
<svg width="26" height="26" viewBox="0 0 23 23" title="Tailscale" fill="none" xmlns="http://www.w3.org/2000/svg"
class="flex-shrink-0 mr-4">
@ -88,13 +88,12 @@
</div>
<a href="#" class="mb-4 link font-medium js-loginButton" target="_blank">Reauthenticate</a>
{{ end }}
</main>
<script>
(function () {
let loginButtons = document.querySelectorAll(".js-loginButton");
let fetchingUrl = false;
</main>
<script>(function () {
let loginButtons = document.querySelectorAll(".js-loginButton");
let fetchingUrl = false;
function handleClick(e) {
function handleClick(e) {
e.preventDefault();
if (fetchingUrl) {
@ -112,8 +111,6 @@
nextUrl.search = nextParams.toString()
const url = nextUrl.toString();
const tab = window.open("/redirect", "_blank");
fetch(url, {
method: "POST",
headers: {
@ -128,23 +125,19 @@
}
const url = res["url"];
if (url) {
authUrl = url;
tab.location = url;
tab.focus();
document.location.href = url;
} else {
location.reload();
}
}).catch(err => {
tab.close();
alert("Failed to log in: " + err.message);
});
}
}
Array.from(loginButtons).forEach(el => {
Array.from(loginButtons).forEach(el => {
el.addEventListener("click", handleClick);
})
})();
</script>
})
})();</script>
</body>
</html>