Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions apps/backend/src/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ export async function authRoutes(app: FastifyInstance) {
// GitHub OAuth callback
app.get('/github/callback', async (request: FastifyRequest<{ Querystring: OAuthCallbackQuery }>, reply: FastifyReply) => {
const { code, state } = request.query;
const storedState = (request.cookies as any)?.oauth_state;

const storedState = request.cookies?.oauth_state;
if (!state || !storedState || state !== storedState) {
return reply.status(400).send({ error: 'Invalid or missing OAuth state — possible CSRF attack' });
}
Expand Down Expand Up @@ -183,7 +182,8 @@ export async function authRoutes(app: FastifyInstance) {
// Google callback
app.get('/google/callback', async (request: FastifyRequest<{ Querystring: OAuthCallbackQuery }>, reply: FastifyReply) => {
const { code, state } = request.query;
const storedState = (request.cookies as any)?.oauth_state;

const storedState = request.cookies?.oauth_state;
if (!state || !storedState || state !== storedState) {
return reply.status(400).send({ error: 'Invalid or missing OAuth state — possible CSRF attack' });
}
Expand Down
8 changes: 8 additions & 0 deletions apps/backend/src/types/fastify.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import '@fastify/cookie';
import { FastifyRequest } from 'fastify';

declare module 'fastify' {
interface FastifyRequest {
cookies: Record<string, string | undefined>;
}
}