Pulastya B commited on
Commit
dd17c4c
·
1 Parent(s): 2a82ed5

Fixed HuggingFace tokens not working

Browse files
Files changed (1) hide show
  1. FRRONTEEEND/lib/supabase.ts +5 -3
FRRONTEEEND/lib/supabase.ts CHANGED
@@ -275,17 +275,19 @@ export const getUserProfile = async (userId: string) => {
275
  }
276
  };
277
 
278
- // Update HuggingFace token for a user
279
  export const updateHuggingFaceToken = async (userId: string, hfToken: string, hfUsername?: string) => {
280
  try {
281
  const { data, error } = await supabase
282
  .from('user_profiles')
283
- .update({
 
284
  huggingface_token: hfToken,
285
  huggingface_username: hfUsername,
286
  updated_at: new Date().toISOString()
 
 
287
  })
288
- .eq('user_id', userId)
289
  .select()
290
  .single();
291
 
 
275
  }
276
  };
277
 
278
+ // Update HuggingFace token for a user (UPSERT to handle new users)
279
  export const updateHuggingFaceToken = async (userId: string, hfToken: string, hfUsername?: string) => {
280
  try {
281
  const { data, error } = await supabase
282
  .from('user_profiles')
283
+ .upsert({
284
+ user_id: userId,
285
  huggingface_token: hfToken,
286
  huggingface_username: hfUsername,
287
  updated_at: new Date().toISOString()
288
+ }, {
289
+ onConflict: 'user_id'
290
  })
 
291
  .select()
292
  .single();
293