Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Nuxt 3 User Management example #23416

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Shooteger
Copy link

Updating package versions, as well as .lock file. Adding .env-example file and set runtimeConfig with supabase key

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

It updates the Nuxt 3 User Management example. Newer packages versions to stay accurate, as well as introduce the usage of .env variables.

What is the current behavior?

What is the new behavior?

Additional context

Updating package versions, as well as .lock file. Adding .env-example file and set runtimeConfig with supabase key
Copy link

vercel bot commented Apr 29, 2024

@Shooteger is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@Shooteger
Copy link
Author

Issue to PR here: #23413

@sergor5
Copy link

sergor5 commented May 6, 2024

@Shooteger , I think the handle_new_user function and the trigger of it are missing too.

Could you add it?

https://github.com/supabase/supabase/blob/master/examples/user-management/nextjs-user-management/README.md

create function public.handle_new_user()
returns trigger as $$
begin
  insert into public.profiles (id, username, avatar_url)
  values (new.id, new.raw_user_meta_data->>'username', new.raw_user_meta_data->>'avatar_url');
  return new;
end;
$$ language plpgsql security definer;
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();

@Shooteger
Copy link
Author

Shooteger commented May 8, 2024

@Shooteger , I think the handle_new_user function and the trigger of it are missing too.

Could you add it?

https://github.com/supabase/supabase/blob/master/examples/user-management/nextjs-user-management/README.md

create function public.handle_new_user()
returns trigger as $$
begin
  insert into public.profiles (id, username, avatar_url)
  values (new.id, new.raw_user_meta_data->>'username', new.raw_user_meta_data->>'avatar_url');
  return new;
end;
$$ language plpgsql security definer;
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();

Hello, generally updated the Readme file now. Much clearer now and links are updated. PLS check @sergor5

create function public.handle_new_user()
returns trigger as $$
begin
insert into public.profiles (id, full_name, avatar_url)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we are creating the profiles table with an username column and it is a unique one:

create table profiles (
  id uuid references auth.users not null primary key,
  updated_at timestamp with time zone,
  username text unique,
  full_name text,
  avatar_url text,
  website text,

  constraint username_length check (char_length(username) >= 3)
);

you probably should update this as:

begin
  insert into public.profiles (id, username, full_name, avatar_url)
  values (new.id, new.raw_user_meta_data->>'username', new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url');
  return new;
end;
$$ language plpgsql security definer;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, the table should already be created in the "Database Schema" step. Remove the create part in the Postgres Row level security" section


Run the following command to launch it on `localhost:3000`
### 4. Env vars
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can rename the step sections with a proper number

## Getting Started

Before running this app, you need to create a Supabase project and copy [your credentials](https://supabase.io/docs/guides/with-nuxt-3#get-the-api-keys) to `.env`.
Iniate a new project in Nuxt 3 with `npx nuxi@latest init <project-name>`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After initing the project, the nuxi cli supports auto-installing the modules now as:

npx nuxi module add supabase

so you could make it as the step 2

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.

None yet

2 participants