Skip to content
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
5 changes: 4 additions & 1 deletion backend/user-service/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ [email protected]
SMTP_PASSWORD=scdqcveqpurzzajj

# App URL
APP_URL=http://localhost:3000
APP_URL=http://localhost:3000

# Feature flags
DEFAULT_ADMIN_ON_REGISTER_FEATURE=true
3 changes: 2 additions & 1 deletion backend/user-service/model/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export async function connectToDB() {
}

export async function createUser(username, email, password) {
return new UserModel({ username, email, password }).save();
const isAdmin = process.env.DEFAULT_ADMIN_ON_REGISTER_FEATURE === "true";
return new UserModel({ username, email, password, isAdmin }).save();
}

export async function findUserByEmail(email) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/context/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
};

//const isUserAdmin = isLoggedIn === true && user != null && user.isAdmin;
const isUserAdmin = true;
const isUserAdmin = !!user?.isAdmin;

return (
<AuthContext.Provider
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/presentation/pages/admin/users/UserManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { DeleteUserForm } from "presentation/components/users/DeleteUserForm/Del
import { UpdateUserPrivilegeForm } from "presentation/components/users/UpdateUserPrivilegeForm/UpdateUserPrivilegeForm";
import { useAuth } from "domain/context/AuthContext";
import { SearchBar } from "presentation/components/common/SearchBar";
import { toast } from "react-toastify";
import { handleError } from "presentation/utils/errorHandler";

export const UserManagement: React.FC<{}> = () => {
const [users, setUsers] = useState<User[]>([]);
Expand All @@ -21,8 +23,12 @@ export const UserManagement: React.FC<{}> = () => {

useEffect(() => {
const getAllUsers = async () => {
const users = await userUseCases.getAllUsers();
setUsers(users);
try {
const users = await userUseCases.getAllUsers();
setUsers(users);
} catch (err) {
toast.error(handleError(err));
}
};
getAllUsers();
}, []);
Expand Down
Loading