Commit 1895937
committed
fix(auth): use auth_user_id instead of id when querying users table in backup-pin
authenticateUser() returns the Supabase Auth user object whose .id is the UUID
from auth.users (the Supabase Auth internal table). The application's public
'users' table has its own primary key 'id' and links to Auth via 'auth_user_id'.
The original code queried .eq('id', user.id) which compared the Auth UUID against
the internal PK — a different UUID — so no row was ever matched.
Result of the bug:
- GET /api/auth/backup-pin always returned { hasPin: false } for every user
because .single() got PGRST116 (no rows found) and the code treated missing
row as 'no PIN set'.
- POST /api/auth/backup-pin silently succeeded (UPDATE matched 0 rows) but the
PIN hash was never persisted, leaving the backup PIN feature entirely broken.
Fix: replace both .eq('id', user.id) calls with .eq('auth_user_id', user.id).
Severity: HIGH — backup PIN feature completely non-functional1 parent ca8b9c9 commit 1895937
1 file changed
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
0 commit comments