diff --git a/frontend/src/screens/StationPage.jsx b/frontend/src/screens/StationPage.jsx
index 3813172..35ea7e9 100644
--- a/frontend/src/screens/StationPage.jsx
+++ b/frontend/src/screens/StationPage.jsx
@@ -5,28 +5,33 @@ import LoginButton from "../components/LoginButton";
import { addClientToStation } from "../utils/AddClientToStation";
function StationPage() {
- const { joinCode, username } = useParams();
+ const { stationID } = useParams();
const [clientToken, setClientToken] = useState("");
const [isModalOpen, setIsModalOpen] = useState(false);
const [accessDenied, setAccessDenied] = useState(true);
- useEffect(() => {
- const auth = async () => {
- try {
- const token = await addClientToStation(username, joinCode);
- setClientToken(token);
- setAccessDenied(false);
- } catch (error) {
- console.error("Auth failed:", error);
- setAccessDenied(true);
- }
- };
+ const [userName, setUserName] = useState("");
+ const [joinCode, setJoinCode] = useState("");
- auth();
- }, [joinCode, username]);
+ const auth = async () => {
+ try {
+ const token = await addClientToStation(userName, joinCode);
+ setClientToken(token);
+ setAccessDenied(false);
+ } catch (error) {
+ console.error("Auth failed:", error);
+ setAccessDenied(true);
+ }
+ };
if (accessDenied) {
- return
Waiting for authentication
;
+ return (
+
+
+ );
}
const recommendedSongs = [];
diff --git a/frontend/src/utils/StationsCreate.js b/frontend/src/utils/StationsCreate.js
index 7d5d31f..640629a 100644
--- a/frontend/src/utils/StationsCreate.js
+++ b/frontend/src/utils/StationsCreate.js
@@ -11,18 +11,28 @@ export async function createStation(name, description) {
description: description,
};
- fetch(RADIOSTATION_URL + CREATE_RADIOSTATION_ENDPOINT, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify(body),
- })
- .then((response) => response.json())
- .then((data) => {
- console.log("Station created:", data);
- })
- .catch((error) => {
- console.error("Error creating station:", error);
- });
+ try {
+ const response = await fetch(
+ RADIOSTATION_URL + CREATE_RADIOSTATION_ENDPOINT,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(body),
+ }
+ );
+
+ const data = await response.json();
+
+ if (!response.ok || !data.success) {
+ console.error("Failed to create station:", data.message);
+ throw new Error(data.message || "Unknown error");
+ }
+
+ return data.data.station.joinCode;
+ } catch (error) {
+ console.error("Error connecting client to station:", error);
+ throw error;
+ }
}