Comments (1)
I think the simplest solution is either
- a
public.profiles
table and use ateam_id
column to reference thebasejump.accounts(id)
or - save the account_id into
auth.users
raw_user_metadata
column
I choose something similar to the first option. Since I use personal accounts also, I set it up like auth.users
, public.profiles
, and basejump.accounts
share the same ID, so it makes it easy to cross-reference. Plus I also utilize a slugified, unique username
for routing.
I had to overwrite the basejump.run_new_user_setup()
function tho. Here's the code. You may be able to get along by changing personal_account
to false
, use something else for slug
& name
instead of username
, and using a an extra team_id
or similar column as a foreign key referencing basejump.accounts(id)
on public.profiles
, instead of the id
.
CREATE TABLE IF NOT EXISTS public.profiles
(
id uuid not null references auth.users(id) on delete cascade,
username text not null unique,
......
);
create or replace function basejump.run_new_user_setup()
returns trigger
language plpgsql
security definer
set search_path = public
as
$$
declare
first_account_id uuid;
begin
-- create the new users's personal account
insert into basejump.accounts (name, primary_owner_user_id, personal_account, id, slug, created_by, updated_by)
values (NEW.raw_user_meta_data->>'username', NEW.id, true, NEW.id, NEW.raw_user_meta_data->>'username', NEW.id, NEW.id)
returning id into first_account_id;
-- add them to the account_user table so they can act on it
insert into basejump.account_user (account_id, user_id, account_role)
values (first_account_id, NEW.id, 'owner');
-- create a profile for the user
insert into public.profiles (id, email, username)
values (NEW.id, NEW.email, NEW.raw_user_meta_data->>'username');
return NEW;
end;
$$;
-- trigger the function every time a user is created
create or replace trigger on_auth_user_created
after insert
on auth.users
for each row
execute procedure basejump.run_new_user_setup();
Note: There are plenty of improvement options with this solution. But it was "ok enough" for me.
from basejump.
Related Issues (20)
- Wrong documentation for update_user HOT 4
- Joins on accounts from public schema HOT 4
- Add example on how to allow access to files to team members depending on folder name HOT 5
- Migrate from Legacy to Latest !
- Any plans to check for billing status in RLS ? HOT 3
- error: Module not found lib/types/supabase.ts". HOT 3
- typo in docs HOT 1
- get_personal_account doesn't include email HOT 2
- Small documentation update HOT 3
- This project should use the same copy-paste logic as the UI components HOT 1
- Package issue with vite/react causes build error HOT 1
- Cannot run db reset on remote database HOT 2
- Use new Auth Hooks approach? HOT 1
- Can we use basejump with hosted supabase? HOT 2
- Confused on how to use RPC to get account info. HOT 6
- get_account_members function from documentation does not exist HOT 2
- Is there a recommended way to remove or delete a user from a team? HOT 2
- How can I integrate Basejump in an existing DB
- Invitation should have a reference to the invited user
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from basejump.