d3ro-voice/apps/mobile-rn/src/features/admin/admin-session.ts
2026-08-29 18:33:45 +09:00

15 lines
607 B
TypeScript

import { supabase } from '../../lib/supabase'
import { AdminServiceError } from './admin-service'
export async function requireAdminAccessToken(expectedUserId: string): Promise<string> {
const { data, error } = await supabase.auth.getSession()
const session = data.session
if (error !== null || session === null || session.user.id !== expectedUserId) {
throw new AdminServiceError('auth', null, false)
}
const token = session.access_token.trim()
if (token.length < 20 || token.length > 16_384 || /\s/.test(token)) {
throw new AdminServiceError('auth', null, false)
}
return token
}