wallet.andert.me/src/lib/Login.svelte
2023-08-26 11:25:36 +02:00

18 lines
412 B
Svelte

<script>
import Cookies from "js-cookie";
async function login() {
const response = await fetch("/api/auth", { method: "POST" });
if (!response.ok) {
alert("Login failed");
} else {
let { token } = await response.json();
Cookies.set("token", token);
alert(`Login Success: ${token}`);
console.log(token);
}
}
</script>
<button on:click={login}>Login</button>