veza/apps/web/src/services/csrf.ts

34 lines
729 B
TypeScript
Raw Normal View History

export class CsrfService {
private static instance: CsrfService;
private csrfToken: string | null = null;
2025-12-13 02:34:34 +00:00
private constructor() {}
public static getInstance(): CsrfService {
if (!CsrfService.instance) {
CsrfService.instance = new CsrfService();
}
return CsrfService.instance;
}
public async refreshCsrfToken(): Promise<void> {
2025-12-13 02:34:34 +00:00
// Placeholder: fetch from backend if needed
// this.csrfToken = ...
}
public getCsrfHeaders(): Record<string, string> {
2025-12-13 02:34:34 +00:00
if (!this.csrfToken) {
return {};
}
return {
2025-12-13 02:34:34 +00:00
'X-CSRF-Token': this.csrfToken,
};
}
public clearCsrfToken(): void {
this.csrfToken = null;
}
}
export const csrfService = CsrfService.getInstance();