Skip to content

Commit

Permalink
Merge pull request #99 from adamcohenhillel/add-managed-solution
Browse files Browse the repository at this point in the history
Add a managed solution
  • Loading branch information
adamcohenhillel authored Mar 26, 2024
2 parents e153279 + f3370b9 commit 111e7be
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
49 changes: 49 additions & 0 deletions scripts/managed/new_accnt.py
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()
1 change: 1 addition & 0 deletions scripts/managed/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
supabase==2.4.0
35 changes: 35 additions & 0 deletions supabase/migrations/20240326142114_remote_schema.sql
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));



0 comments on commit 111e7be

Please sign in to comment.