-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from adamcohenhillel/add-managed-solution
Add a managed solution
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from time import sleep | ||
import secrets | ||
|
||
import supabase | ||
|
||
|
||
MAIN_SUPABASE_URL = "" | ||
MAIN_SUPABASE_SERVICE_ROLE = "" | ||
MAIN_SUPABASE_CLIENT = supabase.create_client(MAIN_SUPABASE_URL, MAIN_SUPABASE_SERVICE_ROLE) | ||
|
||
|
||
def get_latest_account_number(): | ||
latest_account = MAIN_SUPABASE_CLIENT.auth.admin.list_users()[0] | ||
if latest_account is None: | ||
return 1 | ||
if not "account_number" in latest_account.user_metadata: | ||
return 1 | ||
else: | ||
return latest_account.user_metadata["account_number"] | ||
|
||
def main(): | ||
user_real_email = input("Enter user real email: ") | ||
|
||
new_account_number = get_latest_account_number() + 1 | ||
formatted_number = str(new_account_number).zfill(4) | ||
email = f'{formatted_number}@adeus.ai' | ||
password = secrets.token_urlsafe(13) | ||
|
||
res = MAIN_SUPABASE_CLIENT.auth.admin.create_user( | ||
attributes={ | ||
"email": email, | ||
"password": password, | ||
"email_confirm": True, | ||
"user_metadata": { | ||
"account_number": new_account_number, | ||
"user_real_email": user_real_email | ||
} | ||
} | ||
) | ||
|
||
|
||
print("\n\n\n\n\n\n--------------\nDetails: ") | ||
print(f"EMAIL: {email}") | ||
print(f"PASS: {password}") | ||
print("--------------\n\n\n\n\n\n\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
supabase==2.4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
drop policy "Enable access for all authed" on "public"."conversations"; | ||
|
||
alter table "public"."conversations" add column "auth_id" uuid not null default auth.uid(); | ||
|
||
alter table "public"."records" add column "auth_id" uuid not null default auth.uid(); | ||
|
||
alter table "public"."records" enable row level security; | ||
|
||
alter table "public"."conversations" add constraint "public_conversations_user_id_fkey" FOREIGN KEY (auth_id) REFERENCES auth.users(id) ON DELETE CASCADE not valid; | ||
|
||
alter table "public"."conversations" validate constraint "public_conversations_user_id_fkey"; | ||
|
||
alter table "public"."records" add constraint "public_records_user_id_fkey" FOREIGN KEY (auth_id) REFERENCES auth.users(id) ON DELETE CASCADE not valid; | ||
|
||
alter table "public"."records" validate constraint "public_records_user_id_fkey"; | ||
|
||
create policy "users can only see and do their own things" | ||
on "public"."conversations" | ||
as permissive | ||
for all | ||
to authenticated | ||
using ((auth.uid() = auth_id)) | ||
with check ((auth.uid() = auth_id)); | ||
|
||
|
||
create policy "users can only see and do their own things" | ||
on "public"."records" | ||
as permissive | ||
for all | ||
to authenticated | ||
using ((auth.uid() = auth_id)) | ||
with check ((auth.uid() = auth_id)); | ||
|
||
|
||
|