Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgilder committed Jan 12, 2025
1 parent 9e3172a commit 5b82c0b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 40 deletions.
1 change: 0 additions & 1 deletion api/src/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ router.post("/add-meeting", async (req, res) => {
}
});


// ADDING HERE TO GET USER INFO:
router.get("/current-user", async (req, res) => {
const { username } = req.query; // Pass username as a query parameter
Expand Down
36 changes: 18 additions & 18 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import AuthCallback from "./pages/auth-callback";
import { useCurrentUser } from "./hooks/useCurrentUser";

function App(): ReactElement {
const username = "kjgilder"; // Replace with dynamic logic when authentication is set up
const { user, error, loading } = useCurrentUser(username);
const username = "kjgilder"; // Replace with dynamic logic when authentication is set up
const { user, error, loading } = useCurrentUser(username);
return (
<div className="App">
<Routes>
Expand All @@ -21,27 +21,27 @@ function App(): ReactElement {
<Route path="/callback" element={<AuthCallback />} />
</Routes>
<div
style={{
position: "fixed",
bottom: "10px",
right: "10px",
backgroundColor: "rgba(0, 0, 0, 0.7)",
color: "white",
padding: "10px",
borderRadius: "5px",
}}
style={{
position: "fixed",
bottom: "10px",
right: "10px",
backgroundColor: "rgba(0, 0, 0, 0.7)",
color: "white",
padding: "10px",
borderRadius: "5px",
}}
>
{loading ? (
<p>Loading user info...</p>
<p>Loading user info...</p>
) : error ? (
<p>Error: {error}</p>
<p>Error: {error}</p>
) : user ? (
<div>
<p>Username: {user.username}</p>
<p>Role: {user.role}</p>
</div>
<div>
<p>Username: {user.username}</p>
<p>Role: {user.role}</p>
</div>
) : (
<p>No user info available</p>
<p>No user info available</p>
)}
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion app/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ export const api: any = {

return await fetch(url, {
method: "GET",
headers: { "Access-Control-Allow-Origin": "*", mode: "no-cors", "Content-Type": "application/json" },
headers: {
"Access-Control-Allow-Origin": "*",
mode: "no-cors",
"Content-Type": "application/json",
},
})
.then(async (res) => {
if (!res.ok) {
Expand Down
44 changes: 24 additions & 20 deletions app/src/hooks/useCurrentUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@ import { useState, useEffect } from "react";
import { api } from "../api";

export const useCurrentUser = (username: string) => {
const [user, setUser] = useState<{ username: string; role: string } | null>(null);
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState<boolean>(true);
const [user, setUser] = useState<{ username: string; role: string } | null>(
null,
);
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState<boolean>(true);

useEffect(() => {
const fetchUser = async () => {
try {
const response = await api.get(`/user/current-user?username=${encodeURIComponent(username)}`);
setUser(response.data);
} catch (err) {
console.error("Error fetching current user:", err);
setError("Failed to fetch user information");
} finally {
setLoading(false);
}
};
useEffect(() => {
const fetchUser = async () => {
try {
const response = await api.get(
`/user/current-user?username=${encodeURIComponent(username)}`,
);
setUser(response.data);
} catch (err) {
console.error("Error fetching current user:", err);
setError("Failed to fetch user information");
} finally {
setLoading(false);
}
};

if (username) {
fetchUser();
}
}, [username]);
if (username) {
fetchUser();
}
}, [username]);

return { user, error, loading };
return { user, error, loading };
};

0 comments on commit 5b82c0b

Please sign in to comment.