timtbdev / Next.js-Blog-App

✨ Multi-User, Full-stack blogging application built with Next.js and Supabase.
https://ink.mn
293 stars 42 forks source link

Failure to Add User Information to the Profiles table after logging in with Google or GitHub #5

Closed Pakile closed 8 months ago

Pakile commented 10 months ago

Description

After logging in with a Google or GitHub account, the system fails to add user information to the profiles table as expected. This poses difficulties in managing and displaying user information.

Steps to Reproduce

  1. Log in with a Google account.
  2. Or login with a GitHub account.
  3. Check the profiles table to see if user information has been added.

Expectation

After logging in with Google or GitHub, user information should be automatically added to the profiles table.

Note

This issue is not present on the ub.cafe site.

DevTechJr commented 10 months ago

I'm facing the same issue 😦

timtbdev commented 10 months ago

Hello,

Did you guys created a profile table and added a trigger to add a row to your public.profiles table every time a user signs up, you can use triggers.

Screenshot 2023-11-24 at 5 11 51 PM

https://supabase.com/docs/guides/auth/managing-user-data

I hope that it'll fix your issue.

smarthug commented 7 months ago

This is trigger I used

-- inserts a row into public.profiles
create or replace function public.handle_new_user()
returns trigger
language plpgsql
security definer
as $$
begin
  INSERT INTO public.profiles (id, updated_at, full_name, avatar_url)
  SELECT
    new.id,
    CURRENT_TIMESTAMP,
    COALESCE(jsonb_extract_path_text(new.raw_user_meta_data, 'full_name'), NULL),
    COALESCE(jsonb_extract_path_text(new.raw_user_meta_data, 'picture'), jsonb_extract_path_text(new.raw_user_meta_data, 'avatar_url'), NULL);
  return new;
end;
$$;
2-fly-4-ai commented 5 months ago

Don't close this issue. It still exists. Anyone downloading this project is going to run into the same issues. The instructions are not clear and do not work correctly.