Skip to content

Commit 1895937

Browse files
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-functional
1 parent ca8b9c9 commit 1895937

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/app/api/auth/backup-pin/route.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export async function GET(request) {
110110
const { data, error } = await getServiceRoleClient()
111111
.from('users')
112112
.select('backup_pin_hash')
113-
.eq('id', user.id)
113+
.eq('auth_user_id', user.id)
114114
.single();
115115

116116
if (error) {
@@ -151,7 +151,7 @@ export async function POST(request) {
151151
const { error } = await getServiceRoleClient()
152152
.from('users')
153153
.update({ backup_pin_hash: pinHash })
154-
.eq('id', user.id);
154+
.eq('auth_user_id', user.id);
155155

156156
if (error) {
157157
console.error('Error setting backup PIN:', error);

0 commit comments

Comments
 (0)