refactor: centralize base64 encoding
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user