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

Signup auth metadata UUID incompatibility. #521

Closed
akarshghale opened this issue Aug 20, 2023 · 1 comment
Closed

Signup auth metadata UUID incompatibility. #521

akarshghale opened this issue Aug 20, 2023 · 1 comment

Comments

@akarshghale
Copy link

akarshghale commented Aug 20, 2023

Describe the bug
I have a function that runs when signing up a user that extracts the metadata and then inserts some values into another table but the issue is inserting values from metadata for columns that require UUID is not possible as UUID is not serialisable in JSON. So I have to send the data as text but the issue is Postgresql throws error saying type expected is of UUID but text given.

To Reproduce

      response = supabase.auth.sign_up({
        "email": email,
        "password": password,
        "options": {
            "data": {
            "first_name": first_name,
            "last_name": last_name,
            "role": role,
            "organization_name": organization_name,
            "organization_id": organization_id
            }
        }
        })

organization_id column ideally requires UUID.

Error
column "organization_id" is of type uuid but expression is of type text

function:
handle_new_user

  begin
    insert into public.users (id, first_name, last_name, organization_name, organization_id, role)
    values (new.id, new.raw_user_meta_data->>'first_name', new.raw_user_meta_data->>'last_name', new.raw_user_meta_data->>'organization_name', new.raw_user_meta_data->>'organization_id', new.raw_user_meta_data->>'role');
return new;
end;
@akarshghale
Copy link
Author

I figured it out!

just had to enclose the required column into uuid()

 begin
    insert into public.users (id, first_name, last_name, organization_name, organization_id, role)
    values (new.id, new.raw_user_meta_data->>'first_name', new.raw_user_meta_data->>'last_name', new.raw_user_meta_data->>'organization_name', uuid(new.raw_user_meta_data->>'organization_id'), new.raw_user_meta_data->>'role');
return new;
end;

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

No branches or pull requests

1 participant