fix: resolve TypeScript errors for CI pipeline
- Fix pg-boss Job type imports (PgBoss.Job -> Job from pg-boss) - Replace deprecated teamConcurrency with localConcurrency - Add null checks for possibly undefined values (clients, import rows) - Fix tone type narrowing in profile.ts - Fix test type assertions (non-null assertions, explicit Record types) - Extract auth middleware into shared module - Fix rate limiter Map generic type
This commit is contained in:
20
src/middleware/auth.ts
Normal file
20
src/middleware/auth.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Elysia } from 'elysia';
|
||||
import { auth, type User } from '../lib/auth';
|
||||
|
||||
/**
|
||||
* Auth middleware plugin - adds `user` to the Elysia context.
|
||||
* Import and `.use(authMiddleware)` in route files that need authentication.
|
||||
*/
|
||||
export const authMiddleware = new Elysia({ name: 'auth-middleware' })
|
||||
.derive({ as: 'scoped' }, async ({ request, set }): Promise<{ user: User }> => {
|
||||
const session = await auth.api.getSession({
|
||||
headers: request.headers,
|
||||
});
|
||||
|
||||
if (!session?.user) {
|
||||
set.status = 401;
|
||||
throw new Error('Unauthorized');
|
||||
}
|
||||
|
||||
return { user: session.user as User };
|
||||
});
|
||||
Reference in New Issue
Block a user