Skip to content

Commit 7e2bcc9

Browse files
author
mdatelle
committed
chore: extend FastifyRequest to handle headers
1 parent 6dff277 commit 7e2bcc9

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

api/src/types/fastify.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ import type {
77
export type FastifyInstance = BaseFastifyInstance;
88
export interface FastifyRequest extends BaseFastifyRequest {
99
cookies: Record<string, string | undefined>;
10+
headers: Record<string, string | undefined>;
1011
}
1112
export type FastifyReply = BaseFastifyReply;

api/src/unraid-api/auth/auth.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export class AuthService {
5353
try {
5454
if (
5555
!this.validateCsrfToken(
56-
(request.headers['x-csrf-token'] as string | undefined) ||
57-
((request.query as { csrf_token?: string })?.csrf_token as string | undefined)
56+
request.headers['x-csrf-token'] ||
57+
(request.query as { csrf_token?: string })?.csrf_token
5858
)
5959
) {
6060
throw new UnauthorizedException('Invalid CSRF token');

api/src/unraid-api/auth/cookie.strategy.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable, Logger } from '@nestjs/common';
1+
import { Injectable } from '@nestjs/common';
22
import { PassportStrategy } from '@nestjs/passport';
33

44
import { Strategy } from 'passport-custom';
@@ -11,13 +11,12 @@ const strategyName = 'user-cookie';
1111
@Injectable()
1212
export class UserCookieStrategy extends PassportStrategy(Strategy, strategyName) {
1313
static key = strategyName;
14-
private readonly logger = new Logger(UserCookieStrategy.name);
1514

1615
constructor(private authService: AuthService) {
1716
super();
1817
}
1918

20-
public validate = async (req: FastifyRequest): Promise<any> => {
21-
return this.authService.validateCookiesCasbin(req);
19+
public validate = async (request: FastifyRequest): Promise<any> => {
20+
return this.authService.validateCookiesCasbin(request);
2221
};
2322
}

0 commit comments

Comments
 (0)