crypt does not work on trigger functions
See original GitHub issueBug report
Describe the bug
For some reason crypt
does not work on trigger functions. I tried other functions like md5 and it works. The plugin is enabled, and I’m able to run the function on the SQL section.
To Reproduce
this works:
begin
insert into public."Users" (id, email , name, phone_1, phone_2, id_condo, address, birthday, password )
values (
new.id,
new.email,
new.raw_user_meta_data->>'name',
new.raw_user_meta_data->>'phone_1',
new.raw_user_meta_data->>'phone_2',
(new.raw_user_meta_data->>'id_condo'::text)::uuid,
new.raw_user_meta_data->'address',
CAST (new.raw_user_meta_data->>'birthday' as DATE),
md5( new.raw_user_meta_data->>'password')
);
return new;
end;
but this does not work
begin
insert into public."Users" (id, email , name, phone_1, phone_2, id_condo, address, birthday, password )
values (
new.id,
new.email,
new.raw_user_meta_data->>'name',
new.raw_user_meta_data->>'phone_1',
new.raw_user_meta_data->>'phone_2',
(new.raw_user_meta_data->>'id_condo'::text)::uuid,
new.raw_user_meta_data->'address',
CAST (new.raw_user_meta_data->>'birthday' as DATE),
crypt( new.raw_user_meta_data->>'password', gen_salt('bf', 8))
);
return new;
end;
Expected behavior
crypt should work , so the password should be encrypted
Actual behavior
the trigger functions throws an error
Image

System information
- OS: macOS
- Browser chrome 96.0.4664.55 (Build oficial) (x86_64)
- Version of supabase-js: 1.28.1
- Version of Node.js: v12.20.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
encrypt password trigger - sql - Stack Overflow
The trigger function is basically ok. Some cleanup: CREATE FUNCTION encrypt_password() RETURNS TRIGGER AS $func$ BEGIN NEW.passwd ...
Read more >12.14 Encryption and Compression Functions
The derived key is used to encrypt and decrypt the data, and it remains in the MySQL Server instance and is not accessible...
Read more >postgresql - assignment in trigger function does not work
However, the assignment is not made when the trigger fires. Columns in the update or insert are updated; only the fts_vector column is...
Read more >Documentation: 15: F.28. pgcrypto - PostgreSQL
The pgcrypto module provides cryptographic functions for PostgreSQL. This module is considered “trusted”, that is, it can be installed by non-superusers who ...
Read more >Cloud Functions triggers - Google Cloud
Note: Trigger binding does not happen instantaneously. It may take several minutes for a deployed function to start triggering on incoming events.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So I see you created it in the function editor. I think, but am not sure that user does not have full privileges like the sql editor user (I don’t use it).
Add set search_path = “$user”, public, auth, extensions; to your function and see if that helps. I just copied the function from the discussion I linked above and it works for me.
Thanks for jumping in to help @GaryAustin1 🙏 .
@ichbinedgar - looks like this is working for you now so I’ll close this, but feel free to comment if you need me to reopen