hmm separate question: does supabase or postgres h...
# help
n
hmm separate question: does supabase or postgres have any idea of a get-or-create function?
s
What does this function do?
n
my sql is super rusty, but something pseudocode like
select * from api_keys where api_key.user == user_id else insert (gen_api_key(), user.id) into api_keys and return
s
There isn't anything out of the box from what I know, but you can create a postgres function to do this and call it with the
.rpc()
method of the Supabase client library.
n
hmm ok. I suppose it's probably important to learn postgres functions to work with supabase
thanks
hmm maybe there's another way? I'm using supabase-js on my client web app to talk to my supabase backendend and hoping to use supabase-ui for my auth. What if I put this get_or_create logic behind my own server-side API? I can have the user fetch(/my/api/token) and my server can implement the get or create
but in that case I would need the request to /my/api/token to be authenticated with whatever auth the client-side user has collected. Can I share that auth simply?
looks like maybe? https://supabase.com/docs/reference/javascript/auth-setauth. Not sure I see how to pull the user's JWT out of supabase-ui
aha, ok got it