Sessions 5-7a: 955 tests, deployment ready

This commit is contained in:
Kev
2026-06-08 18:35:13 -04:00
parent 06b82624a2
commit 1fa04dc776
371 changed files with 49366 additions and 955 deletions
+39
View File
@@ -0,0 +1,39 @@
import { NextRequest } from 'next/server';
import { getServerSupabase } from './supabase';
export interface AuthedUser {
id: string;
email: string | null;
tier: 'free' | 'analyst' | 'desk';
}
/**
* Verify a bearer token from the Authorization header against Supabase.
* Returns null when missing/invalid — callers decide whether to 401.
*/
export async function getUserFromRequest(req: NextRequest): Promise<AuthedUser | null> {
const auth = req.headers.get('authorization');
if (!auth || !auth.toLowerCase().startsWith('bearer ')) return null;
const sb = getServerSupabase(auth);
if (!sb) return null;
const { data, error } = await sb.auth.getUser();
if (error || !data.user) return null;
const { data: profile } = await sb
.from('user_profiles')
.select('tier')
.eq('id', data.user.id)
.maybeSingle();
return {
id: data.user.id,
email: data.user.email ?? null,
tier: ((profile?.tier as AuthedUser['tier']) ?? 'free'),
};
}
export function jsonError(status: number, message: string) {
return Response.json({ error: message }, { status });
}