From 943f50f8cbdcc7d7f93832fc40b92dd778e43e85 Mon Sep 17 00:00:00 2001 From: JoshHare Date: Mon, 11 Nov 2024 16:36:28 -0600 Subject: [PATCH 1/3] fixed authentication bug --- .env | 8 ++++---- frontend/src/API/API_Interfaces.tsx | 2 +- frontend/src/pages/logIn.tsx | 4 +--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.env b/.env index ec139b58..01305471 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -MYSQL_ROOT_PASSWORD= # Change to your desired root password -MYSQL_DATABASE= # Replace with your database name -MYSQL_USER= # Replace with your MySQL username -MYSQL_PASSWORD= # Replace with your MySQL password \ No newline at end of file +MYSQL_ROOT_PASSWORD=chemistrycafefall24 # Change to your desired root password +MYSQL_DATABASE=chemistry_db # Replace with your database name +MYSQL_USER=chemistrycafedev # Replace with your MySQL username +MYSQL_PASSWORD=chemistrycafe # Replace with your MySQL password diff --git a/frontend/src/API/API_Interfaces.tsx b/frontend/src/API/API_Interfaces.tsx index 75b245ce..61090fd2 100644 --- a/frontend/src/API/API_Interfaces.tsx +++ b/frontend/src/API/API_Interfaces.tsx @@ -69,7 +69,7 @@ export interface ReactionSpeciesDto { } export interface User { - id: string; + id?: string; username: string; role: string; email?: string | null; diff --git a/frontend/src/pages/logIn.tsx b/frontend/src/pages/logIn.tsx index 412a95e6..0265cdb9 100644 --- a/frontend/src/pages/logIn.tsx +++ b/frontend/src/pages/logIn.tsx @@ -72,7 +72,6 @@ const LogIn = () => { // Check if the user already exists in the database try { const existingUser = await getUserByEmail(profileData.email); - if (existingUser) { const updatedUser = { access_token: user.access_token, @@ -89,7 +88,6 @@ const LogIn = () => { setUser(contextUser); } else { const newUser = { - id: "", username: profileData.name, email: profileData.email, role: "unverified", @@ -113,7 +111,7 @@ const LogIn = () => { } } catch (error) { console.error("Error checking or creating user:", error); - alert("Error checking or creating user"); + alert("Error checking or creating user" + error); } }) .catch((error) => { From d8fbce523f054e120a2940e7370afade77122fa6 Mon Sep 17 00:00:00 2001 From: JoshHare Date: Mon, 11 Nov 2024 17:20:35 -0600 Subject: [PATCH 2/3] more bug fixes --- frontend/src/pages/logIn.tsx | 3 +-- init.sql | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/logIn.tsx b/frontend/src/pages/logIn.tsx index 0265cdb9..88ae3685 100644 --- a/frontend/src/pages/logIn.tsx +++ b/frontend/src/pages/logIn.tsx @@ -105,9 +105,8 @@ const LogIn = () => { email: createdUser.email, role: createdUser.role || "unverified", }; - setUser(contextUser); + setUser(createdUser); console.log("Context user ", contextUser); - alert("New user created successfully"); } } catch (error) { console.error("Error checking or creating user:", error); diff --git a/init.sql b/init.sql index b4399acc..b8457729 100644 --- a/init.sql +++ b/init.sql @@ -798,6 +798,7 @@ INSERT IGNORE INTO users (id, username, role, email) VALUES (UUID(), 'Joshua Hare', 'admin', 'jmhhare@tamu.edu'), (UUID(), 'Nishka Mittal', 'admin', 'nishka06@tamu.edu'), (UUID(), 'Sydney Ferris', 'admin', 'sferris@tamu.edu'), + (UUID(), 'Britt Schiller', 'admin', 'brittschiller@tamu.edu'), (UUID(), 'Kyle Shores', 'admin', 'kshores@ucar.edu'); -- Link users to mechanisms From 9f314885667c8da4ea18d9e9d6c60d65f31832d2 Mon Sep 17 00:00:00 2001 From: JoshHare Date: Mon, 11 Nov 2024 21:12:58 -0600 Subject: [PATCH 3/3] ci fixes --- frontend/src/pages/RoleManagement.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/RoleManagement.tsx b/frontend/src/pages/RoleManagement.tsx index e3a1c3c4..e048daa7 100644 --- a/frontend/src/pages/RoleManagement.tsx +++ b/frontend/src/pages/RoleManagement.tsx @@ -68,7 +68,9 @@ const RoleManagement: React.FC = () => { setUsers(response); // Initialize selectedRoles with each user's current role const initialRoles = response.reduce((acc, user) => { - acc[user.id] = user.role; + if(user.id){ + acc[user.id] = user.role; + } return acc; }, {} as { [key: string]: string }); setSelectedRoles(initialRoles);