v3: follows, notifications, invite-only registration, unread markers
This commit is contained in:
32
api/routes/invites.ts
Normal file
32
api/routes/invites.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Router } from "@oak/oak";
|
||||
import { APIErrorCode, APIException } from "../model/interfaces.ts";
|
||||
import { type AuthContext, authMiddleware } from "../middleware/auth.ts";
|
||||
import { createInvite, validateInvite } from "../services/invite-service.ts";
|
||||
|
||||
const router = new Router({ prefix: "/api/invites" });
|
||||
|
||||
// Create a new invite link (any authenticated user)
|
||||
router.post("/", authMiddleware, async (ctx: AuthContext) => {
|
||||
if (!ctx.state.user) {
|
||||
throw new APIException(APIErrorCode.UNAUTHORIZED, 401, "Not authenticated");
|
||||
}
|
||||
const token = await createInvite(ctx.state.user.userId);
|
||||
ctx.response.status = 201;
|
||||
ctx.response.body = { success: true, data: { token } };
|
||||
});
|
||||
|
||||
// Validate an invite token (used by the register page before showing the form)
|
||||
router.get("/:token", async (ctx) => {
|
||||
try {
|
||||
await validateInvite(ctx.params.token);
|
||||
ctx.response.body = { success: true };
|
||||
} catch {
|
||||
throw new APIException(
|
||||
APIErrorCode.NOT_FOUND,
|
||||
404,
|
||||
"Invalid or expired invite",
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user