Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c9f5e39
commits
christianhelp Oct 5, 2025
712a37b
updates db and adds email + password sign up
christianhelp Oct 19, 2025
4d1c40f
Adds bugs to todos
christianhelp Oct 19, 2025
7c585f5
ensures protection of sign in and sign up routes
christianhelp Oct 19, 2025
717a3f9
fix providers setup
christianhelp Oct 21, 2025
5969492
fixes up stuff
christianhelp Oct 24, 2025
b68a3a6
Adds sidebar
christianhelp Oct 24, 2025
1f5fe76
whole bunch of other commits
christianhelp Oct 25, 2025
dae49d6
formatter
christianhelp Oct 25, 2025
e8ace99
changes idk
christianhelp Oct 25, 2025
7a038f5
Merge remote-tracking branch 'origin/main' into other-fixes-n-stuff
christianhelp Oct 25, 2025
0a7ec04
whole lotta stuff
christianhelp Nov 2, 2025
05dd665
formatter
christianhelp Nov 2, 2025
0b79b23
modifies user button
christianhelp Nov 9, 2025
41a5921
adds a bunch of other stuff like theme switcher I think
christianhelp Nov 25, 2025
ee5abcf
I suck at commit messages
christianhelp Dec 17, 2025
23aca39
More commits and stuff
christianhelp Jan 18, 2026
c3ab36d
formatter + stuff
christianhelp Jan 20, 2026
e70e7bb
More commits for formatter and fixes mutations
christianhelp Jan 20, 2026
3c7bc60
updates and fixes imports
christianhelp Jan 25, 2026
a0ee072
formatter
christianhelp Jan 25, 2026
b1998f0
Fixes based on Code Rabbit suggestions (I should pay more attention)
christianhelp Feb 14, 2026
0c2c18c
formatter
christianhelp Feb 14, 2026
0c1aa2f
Updates for more feedback. The bot is cooking ngl.
christianhelp Feb 15, 2026
3bf9077
More feedback
christianhelp Feb 15, 2026
b40414d
fixes
christianhelp Feb 15, 2026
47befbd
more fixes
christianhelp Feb 16, 2026
a849513
Updates to ignore Shad cn components and route tree
christianhelp Feb 16, 2026
f1eaf42
Quick update of feedback for join
christianhelp Feb 16, 2026
25c5458
add todo for extra variables logged that can be nulled
christianhelp Feb 16, 2026
4c5ad4d
Removes undeeded TODOs and adds bugs to a few
christianhelp Feb 16, 2026
d39f303
Renames constants to be screaming snake case
christianhelp Feb 16, 2026
4beff4f
Renames all of the errors
christianhelp Feb 16, 2026
9f47800
Updates all of the routes to have the correct response format
christianhelp Feb 16, 2026
bb02ad9
Quick updates
christianhelp Feb 16, 2026
961a24e
Merge commit '48ca5a82cf10a9393219cdfdd12668dadf95377d' into rework-a…
christianhelp Feb 17, 2026
388c1f6
formatter
christianhelp Feb 17, 2026
e8a7fb8
Small updates
christianhelp Feb 17, 2026
fa08521
more updates or things I missed
christianhelp Feb 17, 2026
a8fcb0c
More updates
christianhelp Feb 17, 2026
051bdef
More fixes
christianhelp Feb 17, 2026
af0fd28
Fixes return for user on admin
christianhelp Feb 17, 2026
2d96af2
whoops
christianhelp Feb 17, 2026
ee9df94
fix type thing
christianhelp Feb 17, 2026
eadef63
Removes old comment
christianhelp Feb 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
authenticatedMiddleware,
afterRouteLogicMiddleware,
} from "./lib/functions/middleware";
import { API_ERROR_MESSAGES } from "shared";

interface Env {}

Expand All @@ -44,7 +45,8 @@ export const api = HonoBetterAuth()

return c.json(
{
error: "Internal Server Error",
message: "An unexpected error occurred.",
code: API_ERROR_MESSAGES.GENERIC_ERROR,
},
500,
);
Expand Down
7 changes: 4 additions & 3 deletions apps/api/src/lib/functions/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ export function isSiteAdminUser(
}

export async function leaveTeam(userId: string, teamId: string) {
await db
return db
.delete(userToTeam)
.where(
and(eq(userToTeam.userId, userId), eq(userToTeam.teamId, teamId)),
);
)
.returning({ teamId: userToTeam.teamId });
}

export async function getAdminUserForTeam(userId: string, teamId: string) {
Expand All @@ -61,7 +62,7 @@ export async function getAdminUserForTeam(userId: string, teamId: string) {
),
});
}

// TODO: This function is lowkey pivotal so we should ensure it is WAI.
export async function isUserSiteAdminOrQueryHasPermissions<T = unknown>(
userSiteRole: SiteRoleType,
// Accept either a Promise (already invoked query) or a function that returns a Promise
Expand Down
15 changes: 9 additions & 6 deletions apps/api/src/lib/functions/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ export async function setUserSessionContextMiddleware(c: Context, next: Next) {
const requestId = nanoid();
c.set("requestId", requestId);

await logInfo(
`Middleware for request path ${c.req.path} for ${userString}`,
c,
);
logInfo(`Middleware for request path ${c.req.path} for ${userString}`, c);

if (!session) {
c.set("user", null);
Expand All @@ -44,8 +41,14 @@ export async function authenticatedMiddleware(c: ApiContext, next: Next) {
const user = c.get("user");
const session = c.get("session");
if (!(user && session)) {
await logInfo(`Unauthorized access attempt to ${c.req.path}`, c);
return c.json({ error: API_ERROR_MESSAGES.notAuthorized }, 401);
logInfo(`Unauthorized access attempt to ${c.req.path}`, c);
return c.json(
{
message: "Please log in.",
code: API_ERROR_MESSAGES.NOT_AUTHENTICATED,
},
401,
);
}
return next();
}
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { log } from "db";
import { SessionType, UserType } from "db/types";
import type { SessionType, UserType } from "db/types";
import type { Context } from "hono";

// Match the Variables shape declared in HonoBetterAuth
Expand Down
30 changes: 25 additions & 5 deletions apps/api/src/routes/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,50 @@ const logHandler = HonoBetterAuth()
.get("/admin/all", async (c) => {
const user = c.get("user");
if (!user || !isSiteAdminUser(user.siteRole)) {
return c.json({ message: API_ERROR_MESSAGES.notAuthorized }, 401);
return c.json(
{
message:
"You are not authorized to access this endpoint. Only site admins can access all logs.",
code: API_ERROR_MESSAGES.NOT_AUTHORIZED,
},
403,
);
}
const allLogs = await db.query.log.findMany();
return c.json({ message: allLogs }, 200);
return c.json({ data: allLogs }, 200);
})
// This route needs to be made to get logs from a team. Logs should be paginated and alllow for basic filtering on the frontend
.get("/:teamId", zValidator("param", teamIdSchema), async (c) => {
const user = c.get("user");
const teamId = c.req.valid("param").teamId;

if (!user) {
return c.json({ message: API_ERROR_MESSAGES.notAuthorized }, 401);
return c.json(
{
message: "Please log in.",
code: API_ERROR_MESSAGES.NOT_AUTHENTICATED,
},
401,
);
}

const hasPermissions = await isUserSiteAdminOrQueryHasPermissions(
user.siteRole,
getAdminUserForTeam(user.id, teamId),
);
if (!hasPermissions) {
return c.json({ message: API_ERROR_MESSAGES.notAuthorized }, 401);
return c.json(
{
message:
"You are not authorized to access this endpoint. Only admins can access team logs.",
code: API_ERROR_MESSAGES.NOT_AUTHORIZED,
},
403,
);
}
const logs = await db.query.log.findMany({
where: eq(log.teamId, teamId),
});
return c.json({ message: logs }, 200);
return c.json({ data: logs }, 200);
});
export default logHandler;
Loading