diff --git a/frontend/src/screens/StationPage.jsx b/frontend/src/screens/StationPage.jsx
index c4830eb..3813172 100644
--- a/frontend/src/screens/StationPage.jsx
+++ b/frontend/src/screens/StationPage.jsx
@@ -1,10 +1,33 @@
-import React, { useState, useParams } from "react";
+import { useParams } from "react-router-dom";
+import React, { useState, useEffect } from "react";
import AddSongModal from "./AddSongModal";
import LoginButton from "../components/LoginButton";
+import { addClientToStation } from "../utils/AddClientToStation";
function StationPage() {
- const { id } = useParams();
+ const { joinCode, username } = 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);
+ }
+ };
+
+ auth();
+ }, [joinCode, username]);
+
+ if (accessDenied) {
+ return
Waiting for authentication
;
+ }
const recommendedSongs = [];
diff --git a/frontend/src/utils/AddClientToStation.js b/frontend/src/utils/AddClientToStation.js
new file mode 100644
index 0000000..a0420b0
--- /dev/null
+++ b/frontend/src/utils/AddClientToStation.js
@@ -0,0 +1,33 @@
+import {
+ RADIOSTATION_URL,
+ ADD_CLIENT_ENDPOINT,
+} from "../constants/ApiConstants";
+
+export async function addClientToStation(username, joinCode) {
+ const body = {
+ username,
+ joinCode,
+ };
+
+ try {
+ const response = await fetch(RADIOSTATION_URL + ADD_CLIENT_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 connect to station:", data.message);
+ throw new Error(data.message || "Unknown error");
+ }
+
+ return data.data.clientToken;
+ } catch (error) {
+ console.error("Error connecting client to station:", error);
+ throw error;
+ }
+}