2023-08-25 10:31:15 +00:00
|
|
|
<script>
|
2023-08-25 12:59:02 +00:00
|
|
|
import Cookies from "js-cookie";
|
2023-08-25 10:31:15 +00:00
|
|
|
async function login() {
|
2023-08-25 12:59:02 +00:00
|
|
|
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}`);
|
|
|
|
}
|
2023-08-25 10:31:15 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<button on:click={login}>Login</button>
|