Skip to content

Commit eccad39

Browse files
committed
add test case and update the code
1 parent d2a5fa4 commit eccad39

File tree

16 files changed

+7277
-1950
lines changed

16 files changed

+7277
-1950
lines changed

API_Gateway/babel.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
[
44
"@babel/preset-env",
55
{
6-
targets: { node: "current" }, // for Node.js environment
6+
targets: { node: "current" },
77
},
88
],
99
],

API_Gateway/jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export default {
22
testEnvironment: "node",
3-
// transform is optional; babel-jest will handle .js files automatically
43
};

Codespace_Service/babel.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
[
44
"@babel/preset-env",
55
{
6-
targets: { node: "current" }, // for Node.js environment
6+
targets: { node: "current" },
77
},
88
],
99
],

Codespace_Service/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export default {
22
testEnvironment: "node",
3-
// transform is optional; babel-jest will handle .js files automatically
3+
44
};

Frontend/package-lock.json

Lines changed: 20 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@monaco-editor/react": "^4.7.0",
16-
"@supabase/supabase-js": "^2.53.0",
16+
"@supabase/supabase-js": "^2.57.4",
1717
"@tailwindcss/vite": "^4.1.11",
1818
"axios": "^1.11.0",
1919
"dotenv": "^17.2.1",

Frontend/src/App.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import CodespaceInvitation from "./Dashboard/AcceptInvite";
1111
import ProfilePage from "./Dashboard/profile";
1212
import SettingsPage from "./Dashboard/ProfileSetting";
1313
import Homepage from "./Home/Homepage";
14-
1514
import {
1615
BrowserRouter as Router,
1716
Routes,
@@ -23,14 +22,12 @@ import { supabase } from "./database/superbase";
2322
import { type Session, type User } from "@supabase/supabase-js";
2423

2524
function App() {
26-
// 🚩 allow undefined for loading state
2725
const [session, setSession] = useState<Session | null | undefined>(undefined);
2826
const lastTokenRef = useRef<string | undefined>(undefined);
2927

3028
useEffect(() => {
3129
console.log("App mounted");
3230

33-
// 🚩 initial session check
3431
supabase.auth.getSession().then(({ data: { session } }) => {
3532
setSession(session ?? null);
3633
if (session) upsertProfile(session.user);
@@ -64,10 +61,9 @@ function App() {
6461
if (error) console.error("Error upserting profile:", error.message);
6562
}
6663

67-
// 🚩 ProtectedRoute now handles loading
6864
function ProtectedRoute({ children }: { children: React.ReactNode }) {
6965
if (session === undefined) {
70-
return <div></div>; // still checking session
66+
return <div></div>;
7167
}
7268
return session ? children : <Navigate to="/login" />;
7369
}
@@ -106,7 +102,12 @@ function App() {
106102
}
107103
/>
108104

109-
<Route path="/codeeditor/:id" element={<CodeEditorPage />} />
105+
<Route path="/codeeditor/:id"
106+
element={
107+
<ProtectedRoute>
108+
<CodeEditorPage />
109+
</ProtectedRoute>}
110+
/>
110111
<Route
111112
path="/codespace/sharebyemail/:invitationId"
112113
element={<CodespaceInvitation />}

Frontend/src/Dashboard/CreateCodespaceModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ function CreateCodespaceModal({ isOpen, onClose, onSubmit }: Props) {
2525

2626
if (success) {
2727
setCodespaceName("");
28-
setLanguage("javascript"); // reset UI
29-
setVisibility("private"); // reset UI
28+
setLanguage("javascript");
29+
setVisibility("private");
3030
onClose();
3131
}
3232
};

Frontend/src/Dashboard/Dashboard.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import CreateCodespaceModal from "./CreateCodespaceModal";
1010
import { useCodespaces } from "./useCodespaces";
1111
import { type ViewMode } from "./codespace.types";
1212
import type { Codespace } from "./codespace.types";
13-
import { useNavigate } from "react-router-dom";
13+
import { useNavigate } from "react-router";
1414

1515
type Props = {
1616
session: Session;
@@ -41,16 +41,17 @@ const Dashboard = ({ session }: Props) => {
4141
return await createCodespace(name);
4242
};
4343

44-
// 🚩 check invitationId and redirect
44+
45+
46+
// handle invitation link redirect
4547
useEffect(() => {
4648
if (invitationId) {
47-
// clear after using, so it doesn’t loop
4849
localStorage.removeItem("invitationId");
4950
navigate(`/codespace/sharebyemail/${invitationId}`);
5051
}
5152
}, [invitationId, navigate]);
5253

53-
// 🚩 first load spinner
54+
5455
useEffect(() => {
5556
const timer = setTimeout(() => setFirstLoad(false), 1000);
5657
return () => clearTimeout(timer);

Frontend/src/components/login.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { supabase } from "../database/superbase";
2-
import { useEffect, useState } from "react";
2+
import { useState } from "react";
33
import { useNavigate } from "react-router";
44
import { useTheme } from "../ThemeProvider";
55
import { AlertCircle, Sun, Moon, Code } from "lucide-react";
66

7-
// Simple theme toggle button
87
const ThemeToggleButton = () => {
98
const { toggleTheme, isDark, theme } = useTheme();
109

@@ -32,16 +31,6 @@ function Login() {
3231
const [error, setError] = useState<string | null>(null);
3332
const [loading, setLoading] = useState(false);
3433

35-
// Redirect if session exists
36-
useEffect(() => {
37-
const checkSession = async () => {
38-
const {
39-
data: { session },
40-
} = await supabase.auth.getSession();
41-
if (session) navigate("/dashboard");
42-
};
43-
checkSession();
44-
}, [navigate]);
4534

4635
const signInWithGoogle = async () => {
4736
setError(null);
@@ -138,16 +127,6 @@ function Login() {
138127
<label htmlFor="password" className={`text-sm ${theme.text}`}>
139128
Password
140129
</label>
141-
<a
142-
href="#"
143-
className="text-sm text-blue-500 hover:underline"
144-
onClick={(e) => {
145-
e.preventDefault();
146-
// Password reset logic
147-
}}
148-
>
149-
Forgot password?
150-
</a>
151130
</div>
152131
<div className="relative">
153132
<input

0 commit comments

Comments
 (0)