Fix public draft board access not working when setting is enabled

Two bugs were causing the isPublicDraftBoard setting to fail:

1. Draft board loader called getAuth() before checking isPublicDraftBoard.
   Restructured to skip auth entirely for public boards - only call getAuth
   when the board is private and we need to verify member/commissioner access.

2. Settings action saved the league (name + isPublicDraftBoard) AFTER fetching
   the current season. If the season fetch had any issue, updateLeague was never
   reached. Moved the league-level save to happen unconditionally before the
   season fetch, so isPublicDraftBoard is always persisted on form submit.

https://claude.ai/code/session_01Jp2tE3YXhx2jdb6CgCnvZy
This commit is contained in:
Claude 2026-02-22 20:58:48 +00:00
parent 8a444a51a1
commit 4c5414166e
No known key found for this signature in database
2 changed files with 38 additions and 28 deletions

View file

@ -10,8 +10,6 @@ import { useState, useEffect } from "react";
export async function loader(args: any) { export async function loader(args: any) {
const { params } = args; const { params } = args;
const { seasonId } = params; const { seasonId } = params;
const auth = await getAuth(args);
const userId = (auth as any).userId as string | null;
if (!seasonId) { if (!seasonId) {
throw new Response("Season ID is required", { status: 400 }); throw new Response("Season ID is required", { status: 400 });
@ -31,10 +29,16 @@ export async function loader(args: any) {
throw new Response("Season not found", { status: 404 }); throw new Response("Season not found", { status: 404 });
} }
// Check access: allow if public OR user is a league member/commissioner // Check access: public boards are accessible to everyone without auth
let hasAccess = season.league.isPublicDraftBoard; if (!season.league.isPublicDraftBoard) {
// Not public - check if the user is a league member or commissioner
const auth = await getAuth(args);
const userId = (auth as any).userId as string | null;
if (!userId) {
throw new Response("This draft board is not public", { status: 403 });
}
if (!hasAccess && userId) {
// Check if user is a commissioner // Check if user is a commissioner
const isCommissioner = await db.query.commissioners.findFirst({ const isCommissioner = await db.query.commissioners.findFirst({
where: and( where: and(
@ -51,11 +55,9 @@ export async function loader(args: any) {
), ),
}); });
hasAccess = !!(isCommissioner || hasTeam); if (!isCommissioner && !hasTeam) {
} throw new Response("This draft board is not public", { status: 403 });
}
if (!hasAccess) {
throw new Response("This draft board is not public", { status: 403 });
} }
// Get draft slots (draft order) // Get draft slots (draft order)

View file

@ -178,9 +178,31 @@ export async function action(args: Route.ActionArgs) {
const formData = await request.formData(); const formData = await request.formData();
const intent = formData.get("intent"); const intent = formData.get("intent");
// For league-level settings (name, public draft board), save immediately
// before checking season, so they work even if no season exists
if (intent === "update") {
const name = formData.get("name");
const isPublicDraftBoard = formData.get("isPublicDraftBoard") === "on";
if (typeof name !== "string" || !name.trim()) {
return { error: "League name is required" };
}
if (name.trim().length < 3 || name.trim().length > 50) {
return { error: "League name must be between 3 and 50 characters" };
}
await updateLeague(leagueId, {
name: name.trim(),
isPublicDraftBoard,
});
}
// Get current season to check status // Get current season to check status
const season = await findCurrentSeasonWithSports(leagueId); const season = await findCurrentSeasonWithSports(leagueId);
if (!season) { if (!season) {
if (intent === "update") {
return redirect(`/leagues/${leagueId}?updated=true`);
}
return { error: "No active season found" }; return { error: "No active season found" };
} }
@ -345,12 +367,10 @@ export async function action(args: Route.ActionArgs) {
} }
if (intent === "update") { if (intent === "update") {
const name = formData.get("name");
const teamCount = formData.get("teamCount"); const teamCount = formData.get("teamCount");
const draftDateTime = formData.get("draftDateTime"); const draftDateTime = formData.get("draftDateTime");
const draftRounds = formData.get("draftRounds"); const draftRounds = formData.get("draftRounds");
const draftSpeed = formData.get("draftSpeed"); const draftSpeed = formData.get("draftSpeed");
const isPublicDraftBoard = formData.get("isPublicDraftBoard") === "on";
// Map draft speed to time values // Map draft speed to time values
let draftInitialTime: number; let draftInitialTime: number;
@ -378,21 +398,9 @@ export async function action(args: Route.ActionArgs) {
draftIncrementTime = 15; draftIncrementTime = 15;
} }
// Validation // League-level fields (name, isPublicDraftBoard) are already saved above.
if (typeof name !== "string" || !name.trim()) { // Now handle season-specific updates.
return { error: "League name is required" };
}
if (name.trim().length < 3 || name.trim().length > 50) {
return { error: "League name must be between 3 and 50 characters" };
}
try { try {
await updateLeague(leagueId, {
name: name.trim(),
isPublicDraftBoard,
});
// Update season settings // Update season settings
const seasonUpdates: any = {}; const seasonUpdates: any = {};