Closed MichealReed closed 1 year ago
The issue was CORS, there is a need to handle request.method to ensure that all appropriate headers are added preflight.
to mirror https://supabase.com/docs/guides/functions/cors in dart:
const defaults = {
'Access-Control-Allow-Methods': 'POST',
'Access-Control-Allow-Headers':
'apikey, Authorization, X-Client-Info, Origin, X-Requested-With, Content-Type, Accept'
};
const corsAll = {...defaults, 'Access-Control-Allow-Origin': '*'};
void main() {
SupabaseFunctions(fetch: (request) async {
if (request.method == 'OPTIONS') {
return Response('ok', status: 200, headers: edge.Headers(corsAll));
}
final token = request.headers['Authorization']?.split(' ')[1];
final data = await request.json() as Map<String, dynamic>;
return Response(
json.encode({'message': 'Message created!'}),
status: 200,
headers: edge.Headers({...corsAll}),
);
});
}
Error:
Example:
When attempting to get the data included with a request payload I see this. I have not been able to find a way to properly receive the json from the request.