Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 | 368x 18x 350x | import { UnauthorizedError } from "./errors";
// Narrow a possibly-null session user to a non-null one, throwing the standard
// 401 error otherwise. Cheaper than littering route handlers with manual checks.
export function requireUser<T extends { id: string }>(
user: T | null | undefined,
): T {
if (!user) {
throw new UnauthorizedError("User session not found");
}
return user;
}
|