question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

crypt does not work on trigger functions

See original GitHub issue

Bug 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

Screen Shot 2021-11-30 at 11 25 13

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:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
GaryAustin1commented, Nov 30, 2021

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.

0reactions
kiwicopplecommented, Dec 1, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found