Skip to content

Commit cc81302

Browse files
committed
Merge branch 'main' into deploy-risky
2 parents 556c718 + acc31c6 commit cc81302

File tree

6 files changed

+56
-61
lines changed

6 files changed

+56
-61
lines changed

collab/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ func handleMessages(
319319

320320
if msgData.Type == CLOSE_SESSION {
321321
closeMessage := Message{
322+
Type: CLOSE_SESSION,
322323
RoomID: client.roomID,
323324
Content: "The session has been closed by a user.",
324325
Type: msgData.Type,

peerprep/app/actions/server_actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export async function hydrateUid(): Promise<null | UserData> {
9595
if (isError(json)) {
9696
console.log("Failed to fetch user ID.");
9797
console.log(`Error ${json.status}: ${json.error}`);
98-
redirect("/auth/logout");
98+
// redirect("/auth/logout");
9999
}
100100
// TODO: handle error handling
101101
const response = json as UserServiceResponse;

peerprep/app/questions/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ import { hydrateUid } from "../actions/server_actions";
66
import { isError, Question, StatusBody, UserData } from "@/api/structs";
77
import { UserInfoProvider } from "@/contexts/UserInfoContext";
88
import { fetchAllQuestions } from "@/app/questions/helper";
9+
import { redirect } from "next/navigation";
910

1011
async function QuestionsPage() {
1112
const userData = (await hydrateUid()) as UserData;
1213

14+
if (!userData) {
15+
redirect("/auth/login");
16+
}
17+
1318
const questions: Question[] | StatusBody = await fetchAllQuestions();
1419

1520
if (isError(questions)) {

peerprep/components/navbar/ProfileDropdown.tsx

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
"use client";
2-
31
import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/react";
42
import Image from "next/image";
53
import React from "react";
64
import Link from "next/link";
5+
import { UserData } from "@/api/structs";
6+
import { hydrateUid } from "@/app/actions/server_actions";
7+
8+
export const ProfileDropdown = async () => {
9+
let userData;
10+
try {
11+
userData = (await hydrateUid()) as UserData;
12+
} catch {
13+
userData = null;
14+
console.error("Error hydrating user data.");
15+
}
716

8-
export const ProfileDropdown = () => {
917
return (
1018
<div className="absolute inset-y-0 right-0 flex items-center pr-2 sm:static sm:inset-auto sm:ml-6 sm:pr-0">
1119
{/* Profile dropdown */}
@@ -27,30 +35,34 @@ export const ProfileDropdown = () => {
2735
transition
2836
className="absolute right-0 z-10 mt-2 w-48 origin-top-right rounded-md bg-gray-1 py-1 shadow-lg ring-1 ring-black ring-opacity-5 transition focus:outline-none data-[closed]:scale-95 data-[closed]:transform data-[closed]:opacity-0 data-[enter]:duration-100 data-[leave]:duration-75 data-[enter]:ease-out data-[leave]:ease-in"
2937
>
30-
<MenuItem>
31-
<Link
32-
href="#"
33-
className="block px-4 py-2 text-sm data-[focus]:bg-gray-2"
34-
>
35-
Your Profile (Coming Soon)
36-
</Link>
37-
</MenuItem>
38-
<MenuItem>
39-
<Link
40-
href="#"
41-
className="block px-4 py-2 text-sm data-[focus]:bg-gray-2"
42-
>
43-
Settings (Coming Soon)
44-
</Link>
45-
</MenuItem>
46-
<MenuItem>
47-
<Link
48-
href="/auth/logout"
49-
className="block px-4 py-2 text-sm data-[focus]:bg-gray-2"
50-
>
51-
Sign out
52-
</Link>
53-
</MenuItem>
38+
{userData ? (
39+
<>
40+
<MenuItem>
41+
<div className="block px-4 py-2 text-sm text-white data-[focus]:bg-gray-2">
42+
Hello, {userData.username}!
43+
</div>
44+
</MenuItem>
45+
<MenuItem>
46+
<Link
47+
href="/auth/logout"
48+
className="block px-4 py-2 text-sm data-[focus]:bg-gray-2"
49+
>
50+
Sign out
51+
</Link>
52+
</MenuItem>
53+
</>
54+
) : (
55+
<>
56+
<MenuItem>
57+
<Link
58+
href="/auth/login"
59+
className="block px-4 py-2 text-sm data-[focus]:bg-gray-2"
60+
>
61+
Login
62+
</Link>
63+
</MenuItem>
64+
</>
65+
)}
5466
</MenuItems>
5567
</Menu>
5668
</div>

peerprep/components/shared/TitleBar.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

peerprep/middleware.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
import { cookies } from "next/headers";
22
import { NextRequest, NextResponse } from "next/server";
3+
import { CookieNames } from "@/app/actions/session";
34

4-
const protectedRoutes = ["/questions/*", "/user/*"];
5-
const publicRoutes = ["/", "/auth/login/", "/auth/register"];
5+
const protectedRoutes = ["/questions", "/user"];
66

77
const isValidSession = () => {
88
return cookies().has("session");
99
};
1010

1111
export async function middleware(request: NextRequest) {
1212
const path = request.nextUrl.pathname;
13-
const isProtectedRoute = protectedRoutes.includes(path);
14-
const isPublicRoute = publicRoutes.includes(path);
15-
16-
if (isPublicRoute) {
17-
return NextResponse.next();
18-
}
13+
const isProtectedRoute = protectedRoutes.some((route) => path.startsWith(route));
1914

2015
// UNCOMMENT AND ADD TO ENV IF JUST TESTING FRONTEND STUFF
2116
if (process.env.NEXT_BYPASS_LOGIN === "yesplease") {
@@ -27,8 +22,13 @@ export async function middleware(request: NextRequest) {
2722
}
2823

2924
if (path === "/auth/logout" || path === "/auth/logout/") {
30-
let response = NextResponse.redirect(new URL("/auth/login", request.url));
31-
response.cookies.delete("session");
25+
const response = NextResponse.redirect(new URL("/auth/login", request.url));
26+
27+
for (const cookieName of Object.values(CookieNames)) {
28+
response.cookies.delete(cookieName.valueOf());
29+
}
30+
// response.cookies.delete("session");
31+
3232
return response;
3333
}
3434

0 commit comments

Comments
 (0)