feat: add magic-link admin login and speaker materials portal

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
committed 2026-10-07 18:27:56 +02:00
1 parent 0b6d1f2b6f
commit 68fecc2ad1
28 files changed
+1623 -232

No files matched your search

+18 -8
View File
@@ -232,14 +232,23 @@ export async function getMySpeakerSessions(email: string): Promise<string[]> {
* The path is persisted via the `set_session_material` RPC (the sessions table
* is admin-write only, so speakers need the security-definer RPC). */
export async function uploadSessionMaterial(sessionId: string, file: File): Promise<string> {
const path = `sessions/${sessionId}/${Date.now()}-${file.name.replace(/[^a-zA-Z0-9._-]/g, '_')}`;
const { error: upErr } = await supabase.storage.from('materials').upload(path, file, { upsert: true });
const { data: previous, error: readError } = await supabase.from('sessions').select('material_path').eq('id', sessionId).single();
if (readError) throw new ApiError(readError.message);
const path = `sessions/${sessionId}/${crypto.randomUUID()}-${file.name.replace(/[^a-zA-Z0-9._-]/g, '_')}`;
const { error: upErr } = await supabase.storage.from('materials').upload(path, file, { upsert: false });
if (upErr) throw new ApiError(upErr.message);
const { error: dbErr } = await supabase.rpc('set_session_material', {
p_session_id: sessionId,
p_material_path: path,
});
if (dbErr) throw new ApiError(dbErr.message);
if (dbErr) {
const { error: cleanupError } = await supabase.storage.from('materials').remove([path]);
throw new ApiError(`${dbErr.message}${cleanupError ? ' The unattached upload could not be cleaned up.' : ''}`);
}
if (previous.material_path && previous.material_path !== path) {
const { error: cleanupError } = await supabase.storage.from('materials').remove([previous.material_path]);
if (cleanupError) throw new ApiError('Material saved, but the previous file could not be removed. Refresh to see the saved material.');
}
return path;
}
@@ -247,15 +256,16 @@ export async function uploadSessionMaterial(sessionId: string, file: File): Prom
* can delete their own material to re-upload; the path is cleared via the
* `set_session_material` RPC (sessions is admin-write only). */
export async function removeSessionMaterial(sessionId: string): Promise<void> {
const { data } = await supabase.from('sessions').select('material_path').eq('id', sessionId).maybeSingle();
const { data, error: readError } = await supabase.from('sessions').select('material_path').eq('id', sessionId).single();
if (readError) throw new ApiError(readError.message);
const path = (data as Session | null)?.material_path;
if (path) {
const { error: rmErr } = await supabase.storage.from('materials').remove([path]);
if (rmErr) throw new ApiError(rmErr.message);
}
const { error: dbErr } = await supabase.rpc('set_session_material', {
p_session_id: sessionId,
p_material_path: null,
});
if (dbErr) throw new ApiError(dbErr.message);
if (path) {
const { error: rmErr } = await supabase.storage.from('materials').remove([path]);
if (rmErr) throw new ApiError('Material detached, but the file could not be removed from storage.');
}
}