managarten/apps-archived/maerchenzauber/apps/backend/test/custom-auth-test.ts
Till-JS 61d181fbc2 chore: archive inactive projects to apps-archived/
Move inactive projects out of active workspace:
- bauntown (community website)
- maerchenzauber (AI story generation)
- memoro (voice memo app)
- news (news aggregation)
- nutriphi (nutrition tracking)
- reader (reading app)
- uload (URL shortener)
- wisekeep (AI wisdom extraction)

Update CLAUDE.md documentation:
- Add presi to active projects
- Document archived projects section
- Update workspace configuration

Archived apps can be re-activated by moving back to apps/

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 07:03:59 +01:00

77 lines
2.6 KiB
TypeScript

import { createClient, SupabaseClient } from '@supabase/supabase-js';
import * as dotenv from 'dotenv';
import axios from 'axios';
dotenv.config();
async function testCustomAuthentication() {
try {
// Step 1: Get app token from middleware
console.log('Authenticating with middleware...');
const middlewareUrl =
'https://mana-core-middleware-dev-111768794939.europe-west3.run.app/auth/signin';
const appId = '8d2f5ddb-e251-4b3b-8802-84022a7ac77f';
const response = await axios.post(`${middlewareUrl}?appId=${appId}`, {
email: process.env.TEST_USER_EMAIL || 'nils.weiser@memoro.ai',
password: process.env.TEST_USER_PASSWORD || 'Test123!',
});
const { appToken } = response.data;
console.log('Got app token from middleware');
// Step 2: Initialize Supabase client with service role key
// In a real implementation, this would be your SupabaseAuthService
const adminClient = createClient(
process.env.MAERCHENZAUBER_SUPABASE_URL,
process.env.MAERCHENZAUBER_SUPABASE_ANON_KEY
);
// Step 3: Call the custom authentication function
console.log('Authenticating with Supabase using custom token...');
// Using the public wrapper function that calls the auth schema function
const { data: userId, error: authError } = await adminClient.rpc('authenticate_custom_jwt', {
token: appToken,
});
if (authError) {
throw authError;
}
console.log('Successfully authenticated with user ID:', userId);
// Step 4: Create a character with the service role client to bypass RLS
// In a real implementation, we would use proper authentication
console.log('Creating a character...');
// For testing purposes, we'll use the service role client with RLS disabled
const { data: character, error: charError } = await adminClient.rpc('create_test_character', {
p_user_id: userId.toString(),
p_name: 'Test Character',
p_description: 'A test character',
p_prompt: 'Create a test character',
p_image_url: 'https://example.com/main.jpg',
});
if (charError) throw charError;
console.log('Character created:', character.id);
// Step 5: Clean up - delete test data
console.log('Cleaning up test data...');
const { error: deleteCharError } = await adminClient
.from('characters')
.delete()
.eq('id', character.id);
if (deleteCharError) throw deleteCharError;
console.log('Test character deleted');
console.log('All tests passed successfully!');
} catch (error) {
console.error('Test failed:', error);
}
}
testCustomAuthentication()
.then(() => console.log('Test script completed'))
.catch((err) => console.error('Error in test script:', err));