Skip to content

Commit e7eaffd

Browse files
dsshimelclaude
andcommitted
fix student portal showing session expired and pre-cohort dates
The /api/cohorts endpoint requires instructor role, so students calling getCohorts() got a 403 that triggered the session-expired banner and prevented cohort dates from loading. Now /api/auth/me returns cohort dates directly via a JOIN, avoiding the instructor-only endpoint. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c8c13fa commit e7eaffd

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

attendabot/backend/src/api/routes/me.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,31 @@ meRouter.get("/", authenticateToken, (req: AuthRequest, res: Response) => {
1818
studentId?: number;
1919
studentName?: string;
2020
cohortId?: number;
21+
cohortStartDate?: string;
22+
cohortEndDate?: string;
2123
} = {
2224
role: user.role,
2325
name: user.username,
2426
discordAccountId: user.discordAccountId,
2527
};
2628

27-
// If student, look up student record by discord_user_id
29+
// If student, look up student record and cohort dates
2830
if (user.role === "student" && user.discordAccountId) {
2931
const db = getDatabase();
3032
const student = db
31-
.prepare(`SELECT id, name, cohort_id FROM students WHERE discord_user_id = ?`)
32-
.get(user.discordAccountId) as { id: number; name: string; cohort_id: number } | undefined;
33+
.prepare(`
34+
SELECT s.id, s.name, s.cohort_id, c.start_date, c.end_date
35+
FROM students s
36+
JOIN cohorts c ON s.cohort_id = c.id
37+
WHERE s.discord_user_id = ?
38+
`)
39+
.get(user.discordAccountId) as { id: number; name: string; cohort_id: number; start_date: string | null; end_date: string | null } | undefined;
3340
if (student) {
3441
result.studentId = student.id;
3542
result.studentName = student.name;
3643
result.cohortId = student.cohort_id;
44+
if (student.start_date) result.cohortStartDate = student.start_date;
45+
if (student.end_date) result.cohortEndDate = student.end_date;
3746
}
3847
}
3948

attendabot/frontend/src/App.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ function App() {
3030
const [impersonating, setImpersonating] = useState<{ discordId: string; name: string; cohortId: number } | null>(null);
3131
const [impersonateStudents, setImpersonateStudents] = useState<{ discordId: string; name: string; cohortId: number }[]>([]);
3232
const [cohorts, setCohorts] = useState<Cohort[]>([]);
33-
const [studentCohortId, setStudentCohortId] = useState<number | null>(null);
33+
const [studentCohortDates, setStudentCohortDates] = useState<{ startDate?: string; endDate?: string }>({});
3434

3535
/** Fetches the user's role and identity after login. */
3636
const fetchRole = async () => {
3737
const me = await getMe();
3838
if (me) {
3939
setRole(me.role);
40-
if (me.role === "student" && me.cohortId) {
41-
setStudentCohortId(me.cohortId);
42-
const allCohorts = await getCohorts();
43-
setCohorts(allCohorts);
40+
if (me.role === "student") {
41+
setStudentCohortDates({
42+
startDate: me.cohortStartDate,
43+
endDate: me.cohortEndDate,
44+
});
4445
}
4546
}
4647
};
@@ -114,14 +115,13 @@ function App() {
114115

115116
// Student portal
116117
if (role === "student") {
117-
const cohort = cohorts.find((c) => c.id === studentCohortId);
118118
return (
119119
<StudentPortal
120120
username={username}
121121
sessionInvalid={sessionInvalid}
122122
onLogout={handleLogout}
123-
cohortStartDate={cohort?.startDate ?? undefined}
124-
cohortEndDate={cohort?.endDate ?? undefined}
123+
cohortStartDate={studentCohortDates.startDate}
124+
cohortEndDate={studentCohortDates.endDate}
125125
/>
126126
);
127127
}

attendabot/frontend/src/api/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,8 @@ export interface MeResponse {
966966
studentId?: number;
967967
studentName?: string;
968968
cohortId?: number;
969+
cohortStartDate?: string;
970+
cohortEndDate?: string;
969971
}
970972

971973
/** Fetches the current user's role and identity. */

0 commit comments

Comments
 (0)