feat(api): attach session to request in requireAuth
- Add Express Request type augmentation for req.session - requireAuth now sets req.session after session validation, so protected handlers can read the user without calling getSession again - Add ConflictError (409) alongside existing AppError subclasses
This commit is contained in:
parent
cf56399a5e
commit
8c241636bf
3 changed files with 19 additions and 0 deletions
|
|
@ -19,3 +19,9 @@ export class NotFoundError extends AppError {
|
|||
super(message, 404);
|
||||
}
|
||||
}
|
||||
|
||||
export class ConflictError extends AppError {
|
||||
constructor(message: string) {
|
||||
super(message, 409);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,5 +16,7 @@ export const requireAuth = async (
|
|||
return;
|
||||
}
|
||||
|
||||
req.session = session;
|
||||
|
||||
next();
|
||||
};
|
||||
|
|
|
|||
11
apps/api/src/types/express.d.ts
vendored
Normal file
11
apps/api/src/types/express.d.ts
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import type { Session, User } from "better-auth";
|
||||
|
||||
declare global {
|
||||
namespace Express {
|
||||
interface Request {
|
||||
session?: { session: Session; user: User };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
Loading…
Add table
Add a link
Reference in a new issue