From 2ef3bdcd89731c1ed9cb7528181d19b2d9169bb5 Mon Sep 17 00:00:00 2001
From: Paweł Bernaciak <pawelbernaciak@zohomail.eu>
Date: Sat, 21 Oct 2023 11:55:50 +0200
Subject: Add basic frontend to test login

---
 frontend/src/App.tsx | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 frontend/src/App.tsx

(limited to 'frontend/src/App.tsx')

diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
new file mode 100644
index 0000000..996a794
--- /dev/null
+++ b/frontend/src/App.tsx
@@ -0,0 +1,58 @@
+import React from 'react';
+import { CredentialResponse, GoogleLogin } from '@react-oauth/google';
+
+interface LoginResponse {
+    id: number
+}
+
+interface User {
+    id: Number,
+    elements: Element[],
+}
+
+interface Element {
+    id: Number,
+    userId: Number,
+    name: string,
+    state: ElementState,
+}
+
+enum ElementState {
+    HasColor,
+    HasIcon,
+}
+
+function App() {
+    const responseMessage = async (googleResponse: CredentialResponse) => {
+        console.log(googleResponse);
+        const url: string = "/auth/login";
+        const body = {
+            "googleToken": googleResponse.credential
+        };
+
+        const response = await fetch(url, {
+            method: "POST",
+            credentials: "include",
+            mode: "cors",
+            headers: {
+                "Content-Type": "application/json"
+            },
+            body: JSON.stringify(body),
+        });
+        if (!response.ok) {
+            console.log("Backend conection problem");
+            return;
+        }
+
+        const user = await response.json() as LoginResponse;
+        console.log(user);
+    };
+
+    return (
+        <div className="App">
+            <GoogleLogin onSuccess={responseMessage} />
+        </div>
+    );
+}
+
+export default App;
-- 
cgit v1.2.3

