Skip to content

Commit 0a8c36a

Browse files
committed
use dependency injection for cookie prefix in internal client factory
1 parent eb69dfb commit 0a8c36a

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { batchProcess } from '@app/utils.js';
99
/** token for dependency injection of a session cookie options object */
1010
export const SESSION_COOKIE_CONFIG = 'SESSION_COOKIE_CONFIG';
1111

12-
type SessionCookieConfig = {
12+
export type SessionCookieConfig = {
1313
namePrefix: string;
1414
sessionDir: string;
1515
secure: boolean;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ export class LocalSessionService implements OnModuleInit, OnModuleDestroy {
6464
*/
6565
public async getLocalSession(): Promise<string | null> {
6666
try {
67-
const token = await readFile(LocalSessionService.SESSION_FILE_PATH, 'utf-8');
68-
return token.trim();
67+
return await readFile(LocalSessionService.SESSION_FILE_PATH, 'utf-8');
6968
} catch (error) {
70-
this.logger.debug('Local session file not found or not readable');
69+
this.logger.warn(error, 'Local session file not found or not readable');
7170
return null;
7271
}
7372
}

api/src/unraid-api/shared/internal-graphql-client.factory.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Injectable, Logger } from '@nestjs/common';
2-
import { ConfigService } from '@nestjs/config';
1+
import { Inject, Injectable, Logger } from '@nestjs/common';
32

43
import type { InternalGraphQLClientFactory as IInternalGraphQLClientFactory } from '@unraid/shared';
54
import { ApolloClient, InMemoryCache, NormalizedCacheObject } from '@apollo/client/core/index.js';
@@ -14,6 +13,8 @@ import { createClient } from 'graphql-ws';
1413
import { Agent, fetch as undiciFetch } from 'undici';
1514
import WebSocket from 'ws';
1615

16+
import { SESSION_COOKIE_CONFIG, SessionCookieConfig } from '@app/unraid-api/auth/cookie.service.js';
17+
1718
/**
1819
* Factory service for creating internal GraphQL clients.
1920
*
@@ -28,7 +29,8 @@ export class InternalGraphQLClientFactory implements IInternalGraphQLClientFacto
2829
private readonly logger = new Logger(InternalGraphQLClientFactory.name);
2930

3031
constructor(
31-
private readonly configService: ConfigService,
32+
@Inject(SESSION_COOKIE_CONFIG)
33+
private readonly sessionCookieConfig: SessionCookieConfig,
3234
private readonly socketConfig: SocketConfigService
3335
) {}
3436

@@ -143,7 +145,7 @@ export class InternalGraphQLClientFactory implements IInternalGraphQLClientFacto
143145
headers: {
144146
...headers,
145147
'x-csrf-token': cookieAuth.csrfToken,
146-
cookie: `unraid_${cookieAuth.sessionId}=${cookieAuth.sessionId}`,
148+
cookie: `${this.sessionCookieConfig.namePrefix}${cookieAuth.sessionId}=${cookieAuth.sessionId}`,
147149
},
148150
};
149151
}

0 commit comments

Comments
 (0)