complete registration and login
This commit is contained in:
33
src/login.ts
33
src/login.ts
@@ -5,15 +5,34 @@ import "@/main.css";
|
||||
|
||||
// LIBRARIES
|
||||
import $ from "jquery";
|
||||
// import { FilterSpecification, Map, config } from "@maptiler/sdk";
|
||||
// import { createIcons, Locate, LocateFixed } from "lucide";
|
||||
import { LoginResponse } from "./types/types";
|
||||
|
||||
console.log("login");
|
||||
if (localStorage.getItem("token")) {
|
||||
location.replace("/");
|
||||
}
|
||||
|
||||
$("#login").on("submit", (e) => {
|
||||
const API_SERVER = import.meta.env.VITE_API_SERVER!;
|
||||
|
||||
$("#login").on("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const email = $("#email").val();
|
||||
const password = $("#password").val();
|
||||
const email = $("#email");
|
||||
const password = $("#password");
|
||||
|
||||
console.log(email, password);
|
||||
fetch(`${API_SERVER}/api/v1/login`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
email: email.val(),
|
||||
password: password.val(),
|
||||
}),
|
||||
}).then(async (response) => {
|
||||
if (response.ok) {
|
||||
const loginResponse = (await response.json()) as LoginResponse;
|
||||
if (loginResponse.token) {
|
||||
localStorage.setItem("token", loginResponse.token);
|
||||
location.replace("/");
|
||||
} else {
|
||||
console.error("Login failed", loginResponse);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user