async function createTestUser(prefix) {
const email = `${prefix}${randomName()}@example.com`;
const password = 'TestPass123!';
const {data, error} = await supabaseClient.auth.admin.createUser({
email,
password,
email_confirm: true,
});
if (error) {
throw new Error(`Error creating ${prefix}: ${error.message}`);
}
const token = await signInTestUser(email, password);
const client = createAuthClient(token);
// Validate that the client can access the tenants table
const {error: accessError} = await client.from('tenants').select('id').limit(1);
if (accessError) {
throw new Error(`Test user client cannot access tenants table: ${accessError.message}`);
}
return {id: data.user.id, email: data.user.email, token, client};
}
function createAuthClient(token) {
return createClient(process.env.SUPABASE_URL, process.env.SUPABASE_ANON_KEY, {
global: {
headers: {Authorization: `Bearer ${token}`},
},
});
}
async function createTestUser(prefix) {
const email = `${prefix}${randomName()}@example.com`;
const password = 'TestPass123!';
const {data, error} = await supabaseClient.auth.admin.createUser({
email,
password,
email_confirm: true,
});
if (error) {
throw new Error(`Error creating ${prefix}: ${error.message}`);
}
const token = await signInTestUser(email, password);
const client = createAuthClient(token);
// Validate that the client can access the tenants table
const {error: accessError} = await client.from('tenants').select('id').limit(1);
if (accessError) {
throw new Error(`Test user client cannot access tenants table: ${accessError.message}`);
}
return {id: data.user.id, email: data.user.email, token, client};
}
function createAuthClient(token) {
return createClient(process.env.SUPABASE_URL, process.env.SUPABASE_ANON_KEY, {
global: {
headers: {Authorization: `Bearer ${token}`},
},
});
}