Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed authentication bug #61

Merged
merged 6 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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
MYSQL_PASSWORD=chemistrycafe # Replace with your MySQL password
2 changes: 1 addition & 1 deletion frontend/src/API/API_Interfaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export interface ReactionSpeciesDto {
}

export interface User {
id: string;
id?: string;
username: string;
role: string;
email?: string | null;
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/pages/RoleManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/pages/logIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -89,7 +88,6 @@ const LogIn = () => {
setUser(contextUser);
} else {
const newUser = {
id: "",
username: profileData.name,
email: profileData.email,
role: "unverified",
Expand All @@ -107,13 +105,12 @@ 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);
alert("Error checking or creating user");
alert("Error checking or creating user" + error);
}
})
.catch((error) => {
Expand Down
1 change: 1 addition & 0 deletions init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading