Is there a method to create a unique username when a user signs up?

Essentially, right now when a user signs up a function triggers that creates a public profile for that user.

The username is nullable so my initial thoughts were to create an onboarding flow where the user is asked to select a username.

But, is there a way where I can create a unique username for the user using my function?

This is how my function is structured right now:

begin
  insert into public.profiles(id, username, join_date, private)
  values(new.id, SOMETHING, now(), false);

  return new;
end;
Was this page helpful?