Skip to content

User IDs as strings instead of UUIDs for external auth? #4954

Answered by mansueli
colinclerk asked this question in Questions
Discussion options

You must be logged in to vote

First, you'll need to drop the FK from the storage.objects table:

ALTER TABLE storage.objects 
DROP CONSTRAINT objects_owner_fkey;

Here's a possible workaround for converting any text into uuid by hashing it, then formatting as UUID:

CREATE OR REPLACE FUNCTION convert_to_uuid(input_value text)
RETURNS uuid AS $$
DECLARE
  hash_hex text;
BEGIN
  -- Return null if input_value is null or an empty string
  IF input_value IS NULL OR NULLIF(input_value, '') IS NULL THEN
    RETURN NULL;
  END IF;
  hash_hex := substring(encode(digest(input_value::bytea, 'sha512'), 'hex'), 1, 36);
  RETURN (left(hash_hex, 8) || '-' || right(hash_hex, 4) || '-4' || right(hash_hex, 3) || '-a' || right(hash_hex, 3) ||

Replies: 15 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@novemberkilo
Comment options

Answer selected by mansueli
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@tonyboylehub
Comment options

@skorfmann
Comment options

@tonyboylehub
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet