DSatishchandra commited on
Commit
d4440a7
·
verified ·
1 Parent(s): 6e62d51

Create script.js

Browse files
Files changed (1) hide show
  1. static/script.js +43 -0
static/script.js ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.addEventListener("DOMContentLoaded", () => {
2
+ const signupForm = document.getElementById("signupForm");
3
+ const loginForm = document.getElementById("loginForm");
4
+
5
+ if (signupForm) {
6
+ signupForm.addEventListener("submit", async (e) => {
7
+ e.preventDefault();
8
+ const name = document.getElementById("name").value;
9
+ const email = document.getElementById("email").value;
10
+ const password = document.getElementById("password").value;
11
+
12
+ const response = await fetch("/api/signup", {
13
+ method: "POST",
14
+ headers: { "Content-Type": "application/json" },
15
+ body: JSON.stringify({ name, email, password }),
16
+ });
17
+
18
+ const data = await response.json();
19
+ document.getElementById("signupMessage").innerText = data.message;
20
+ });
21
+ }
22
+
23
+ if (loginForm) {
24
+ loginForm.addEventListener("submit", async (e) => {
25
+ e.preventDefault();
26
+ const email = document.getElementById("email").value;
27
+ const password = document.getElementById("password").value;
28
+
29
+ const response = await fetch("/api/login", {
30
+ method: "POST",
31
+ headers: { "Content-Type": "application/json" },
32
+ body: JSON.stringify({ email, password }),
33
+ });
34
+
35
+ const data = await response.json();
36
+ document.getElementById("loginMessage").innerText = data.message;
37
+
38
+ if (data.redirect) {
39
+ window.location.href = data.redirect;
40
+ }
41
+ });
42
+ }
43
+ });