BUG: `evaluate-assessments` Edge Function always returns 500 error from patient app
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- flutter, supabase
- Domain
- backend, databases, mobile-dev, security
Research direction
Start with the evaluate-assessments Edge Function and the patient app's assessment submission path. Inspect how the Supabase client and Authorization header are created, then check the assessment_results insert and authentication flow. Done means authenticated submissions evaluate successfully, save the result for the logged-in patient, and return the score without a 500 error.
Written by the indexing model from the issue text.
Description
Is there an existing issue for this?
- I have searched the existing issues
What happened?
This issue and related PR were fully identified and analyzed by myself. Claude was only used to assist with writing descriptions in English.
📌 Issue Overview
The evaluate-assessments Edge Function always returns 500 Internal Server Error when submitting an assessment from the patient app. The root cause is twofold: the Edge Function creates a Supabase client with SUPABASE_ANON_KEY (anonymous role) which is blocked by RLS policies requiring authenticated role, and the Flutter client overrides the Authorization header with the anon key instead of forwarding the user's JWT.
🔍 Steps to Reproduce
- Log in as a patient in the patient app
- Navigate to the Assessments screen
- Select any assessment (e.g., AQ-10)
- Answer all questions and submit
🎯 Expected Behavior
The assessment should be evaluated, the result saved to assessment_results table, and the score returned to the patient.
🚨 Actual Behavior
FunctionException(status: 500, details: {"error":"Internal Server Error"}, reasonPhrase: Internal Server Error)
The Edge Function fails silently because:
- The Supabase client is created at module level with anon key → DB operations are blocked by RLS
- The Flutter client explicitly sets
Authorization: Bearer <SUPABASE_ANON_KEY>, overriding the user's JWT thatsupabase_flutterwould normally send automatically patient_idis taken from the request body instead of the authenticated user's JWT (security issue)- No error handling on the
assessment_resultsinsert operation
💡 Suggested Improvements
- Move Supabase client creation inside the request handler with the user's
Authorizationheader forwarded - Use
supabase.auth.getUser()to extractpatient_idfrom the JWT instead of trusting the request body - Remove the custom
Authorizationheader override in the Flutter client —supabase_flutterautomatically sends the user's JWT viafunctions.invoke() - Add error handling for the
assessment_resultsinsert operation
Improvement PR is ready and waiting for #156 been merged and #157 been resolved.
Record
- I agree to follow this project's Code of Conduct
- I want to work on this issue
- Dominant language
- Dart
- Stars
- 30
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from AOSSIE-Org/NeuroTrack
-
fix(therapist): Method marked @override does not override any inherited methodPossibly taken @Muneerali199 claimed this 259 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
AOSSIE-Org/NeuroTrack#198 ·
-
fix: Don't use BuildContext across async gaps (use_build_context_synchronously)Possibly taken @Muneerali199 claimed this 259 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
AOSSIE-Org/NeuroTrack#197 ·
-
fix(patient): Remove unused and duplicate imports across patient appPossibly taken @Muneerali199 claimed this 259 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
AOSSIE-Org/NeuroTrack#195 ·
-
BUG: Therapy details save button has no loading guard, allowing duplicate submissions that inflate patient regression reportsPossibly taken @Varadraj75 claimed this 222 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 68/100
AOSSIE-Org/NeuroTrack#221 ·
-
BUG: Appointment booking ignores selected time slot, every appointment saved at midnight to SupabasePossibly taken @Varadraj75 claimed this 227 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 55/100
AOSSIE-Org/NeuroTrack#219 ·
All issues in AOSSIE-Org/NeuroTrack
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Anxcye/anx-reader#1024 ·
-
[cloud_functions]: Apple platforms ignore custom domains passed as regionPossibly taken @ragavendranbala-TSL claimed this today. OpenNeeds Attention platform: ios platform: macos plugin: functions type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
firebase/flutterfire#19015 · 2 comments ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
RevenueCat/purchases-flutter#2048 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
hajisensai/Fushi#4543 · 3 comments ·
Maintainers usually reply within 1 day
-
[video_player] _updatePosition sets isCompleted=true after 500ms when duration is Duration.zeroOpen
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day