feat: implement runtime and build time env variables for remote access

This commit is contained in:
Ralph Khreish
2025-10-15 16:21:34 +02:00
parent 6bc75c0ac6
commit 218b68a31e
2 changed files with 14 additions and 8 deletions

View File

@@ -7,11 +7,13 @@ import path from 'path';
import { AuthConfig } from './types.js'; import { AuthConfig } from './types.js';
// Single base domain for all URLs // Single base domain for all URLs
// Build-time: process.env.TM_PUBLIC_BASE_DOMAIN gets replaced by tsup's env option // Runtime vars (TM_*) take precedence over build-time vars (TM_PUBLIC_*)
// Build-time: process.env.TM_PUBLIC_BASE_DOMAIN gets replaced by tsdown's env option
// Runtime: process.env.TM_BASE_DOMAIN can override for staging/development
// Default: https://tryhamster.com for production // Default: https://tryhamster.com for production
const BASE_DOMAIN = const BASE_DOMAIN =
process.env.TM_PUBLIC_BASE_DOMAIN || // This gets replaced at build time by tsup process.env.TM_BASE_DOMAIN || // Runtime override (for staging/tux)
'https://tryhamster.com'; process.env.TM_PUBLIC_BASE_DOMAIN; // Build-time (baked into compiled code)
/** /**
* Default authentication configuration * Default authentication configuration
@@ -19,7 +21,7 @@ const BASE_DOMAIN =
*/ */
export const DEFAULT_AUTH_CONFIG: AuthConfig = { export const DEFAULT_AUTH_CONFIG: AuthConfig = {
// Base domain for all services // Base domain for all services
baseUrl: BASE_DOMAIN, baseUrl: BASE_DOMAIN!,
// Configuration directory and file paths // Configuration directory and file paths
configDir: path.join(os.homedir(), '.taskmaster'), configDir: path.join(os.homedir(), '.taskmaster'),

View File

@@ -29,13 +29,17 @@ export class SupabaseAuthClient {
*/ */
getClient(): SupabaseJSClient { getClient(): SupabaseJSClient {
if (!this.client) { if (!this.client) {
// Get Supabase configuration from environment - using TM_PUBLIC prefix // Get Supabase configuration from environment
const supabaseUrl = process.env.TM_PUBLIC_SUPABASE_URL; // Runtime vars (TM_*) take precedence over build-time vars (TM_PUBLIC_*)
const supabaseAnonKey = process.env.TM_PUBLIC_SUPABASE_ANON_KEY; const supabaseUrl =
process.env.TM_SUPABASE_URL || process.env.TM_PUBLIC_SUPABASE_URL;
const supabaseAnonKey =
process.env.TM_SUPABASE_ANON_KEY ||
process.env.TM_PUBLIC_SUPABASE_ANON_KEY;
if (!supabaseUrl || !supabaseAnonKey) { if (!supabaseUrl || !supabaseAnonKey) {
throw new AuthenticationError( throw new AuthenticationError(
'Supabase configuration missing. Please set TM_PUBLIC_SUPABASE_URL and TM_PUBLIC_SUPABASE_ANON_KEY environment variables.', 'Supabase configuration missing. Please set TM_SUPABASE_URL and TM_SUPABASE_ANON_KEY (runtime) or TM_PUBLIC_SUPABASE_URL and TM_PUBLIC_SUPABASE_ANON_KEY (build-time) environment variables.',
'CONFIG_MISSING' 'CONFIG_MISSING'
); );
} }