managarten/maerchenzauber/apps/backend/test/supabase-auth-integration-test.ts
Till-JS e7f5f942f3 chore: initial commit - consolidate 4 projects into monorepo
Projects included:
- maerchenzauber (NestJS backend + Expo mobile + SvelteKit web + Astro landing)
- manacore (Expo mobile + SvelteKit web + Astro landing)
- manadeck (NestJS backend + Expo mobile + SvelteKit web)
- memoro (Expo mobile + SvelteKit web + Astro landing)

This commit preserves the current state before monorepo restructuring.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-22 23:38:24 +01:00

51 lines
1.4 KiB
TypeScript

import { NestFactory } from '@nestjs/core';
import { AppModule } from '../src/app.module';
import { AuthService } from '../src/core/services/auth.service';
async function testSupabaseAuthIntegration() {
// Create a NestJS application instance
const app = await NestFactory.createApplicationContext(AppModule);
try {
// Get the AuthService
const authService = app.get(AuthService);
// Test user data
const userId = 'test-user-id';
const email = 'test@example.com';
// Generate a Supabase-compatible token
const token = await authService.generateSupabaseCompatibleToken(
userId,
email,
);
console.log('Generated Supabase-compatible token:', token);
// Create an authenticated Supabase client
const supabaseClient = authService.getAuthenticatedClient(token);
// Test a simple query to verify authentication
const { data, error } = await supabaseClient
.from('your_table_name')
.select('*')
.limit(1);
if (error) {
console.error('Error querying Supabase with the token:', error);
} else {
console.log(
'Successfully authenticated with Supabase! Sample data:',
data,
);
}
} catch (error) {
console.error('Test failed:', error);
} finally {
await app.close();
}
}
// Run the test
testSupabaseAuthIntegration()
.then(() => console.log('Test completed'))
.catch((err) => console.error('Test error:', err));