Skip to content

[HIGH] fix(auth): use auth_user_id instead of id when querying users table in backup-pin#78

Merged
ralyodio merged 1 commit into
profullstack:masterfrom
katnisscalls99:fix/backup-pin-wrong-user-id-field
Jun 11, 2026
Merged

[HIGH] fix(auth): use auth_user_id instead of id when querying users table in backup-pin#78
ralyodio merged 1 commit into
profullstack:masterfrom
katnisscalls99:fix/backup-pin-wrong-user-id-field

Conversation

@katnisscalls99

Copy link
Copy Markdown
Contributor

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-functional

…n 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-functional
@ralyodio ralyodio merged commit 5a69700 into profullstack:master Jun 11, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants