mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix(api): resolve team name lookup and show server error messages
- Backend: look up teams by name first (frontend sends name, not ID) - Frontend: parse response body on API errors instead of showing generic "API error: 400" — now shows the actual server message (e.g. "Password must be at least 8 characters...")
This commit is contained in:
@@ -369,27 +369,33 @@ export async function authRoutes(app: FastifyInstance): Promise<void> {
|
||||
|
||||
const role = body.role === "admin" ? "admin" : "user";
|
||||
|
||||
// Look up Default team ID
|
||||
const defaultTeam = db
|
||||
.select()
|
||||
.from(schema.teams)
|
||||
.where(eq(schema.teams.name, "Default"))
|
||||
.get();
|
||||
const teamId = (body as { team?: string }).team || defaultTeam?.id || "default-team-00000000";
|
||||
// Resolve team — frontend sends team name (e.g. "Default"), not ID
|
||||
const requestedTeam = (body as { team?: string }).team;
|
||||
let team: string;
|
||||
|
||||
// If a specific team was provided, validate it exists
|
||||
if ((body as { team?: string }).team) {
|
||||
const teamExists = db
|
||||
if (requestedTeam) {
|
||||
// Look up by name first, then fall back to ID
|
||||
const teamByName = db
|
||||
.select()
|
||||
.from(schema.teams)
|
||||
.where(eq(schema.teams.id, (body as { team?: string }).team ?? ""))
|
||||
.where(eq(schema.teams.name, requestedTeam))
|
||||
.get();
|
||||
if (!teamExists)
|
||||
const teamById = teamByName
|
||||
? null
|
||||
: db.select().from(schema.teams).where(eq(schema.teams.id, requestedTeam)).get();
|
||||
const found = teamByName || teamById;
|
||||
if (!found)
|
||||
return reply.status(400).send({ error: "Team not found", code: "VALIDATION_ERROR" });
|
||||
team = found.id;
|
||||
} else {
|
||||
const defaultTeam = db
|
||||
.select()
|
||||
.from(schema.teams)
|
||||
.where(eq(schema.teams.name, "Default"))
|
||||
.get();
|
||||
team = defaultTeam?.id || "default-team-00000000";
|
||||
}
|
||||
|
||||
const team = teamId;
|
||||
|
||||
// Check for duplicate username first (so 409 takes priority over limit)
|
||||
const existing = db
|
||||
.select()
|
||||
|
||||
Reference in New Issue
Block a user