refactor: centralize base64 encoding

This commit is contained in:
William Valentin
2025-09-23 11:27:32 -07:00
parent e3a924c0c6
commit de237fd997
4 changed files with 14 additions and 10 deletions

View File

@@ -9,6 +9,7 @@ import { EmailVerificationToken } from './auth.types';
import type { CouchDBDocument } from '../../types';
import { getDatabaseConfig } from '../../config/unified.config';
import { logger } from '../logging';
import { encodeBase64 } from '../../utils/base64';
export interface PasswordResetToken {
userId: string;
@@ -42,14 +43,8 @@ function fromISO(date: string | Date): Date {
return date instanceof Date ? date : new Date(date);
}
function base64Auth(user: string, pass: string): string {
// btoa may not exist in some environments (e.g., Node). Fallback to Buffer.
if (typeof btoa !== 'undefined') {
return btoa(`${user}:${pass}`);
}
return Buffer.from(`${user}:${pass}`).toString('base64');
}
const base64Auth = (user: string, pass: string): string =>
encodeBase64(`${user}:${pass}`);
export class TokenService {
private couchBaseUrl: string | null = null;