When I do a setAuth with my service token the user...
# help
n
When I do a setAuth with my service token the user remains null, what am I doing wrong? Also the Docs state there should be an error object but there doesn't seem to be one?
n
Hello @Nin! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
n
Copy code
const serviceToken = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')
supabaseClient.auth.setAuth(serviceToken!)
var currentUser = await supabaseClient.auth.api.getUser(serviceToken!)

console.log(currentUser)
This returns a null
All in all, I'm trying to invoke
inviteUserByEmail
and prior to that I'm setting the auth to the service role however I get an error saying
[ { data: null, error: { message: "User not allowed", status: 401 } } ]
both on local and when deployed
n
Ok, clear, that solves my confusion but not my error. I'm still confused as to why inviteUserByEmail doesn't work after I've set the setAuth to the service token
g
Try initializing the client with service role key maybe versus the user...
n
I also need the user in a previous block though
Ah you mean initialize with service role and then use the setAuth when I need it in that block?
But then why would it take the user in that block but not the service role in the other
g
I've not had enough coffee yet to really process auth stuff. If someone else does not come along, I'll read over this again in awhile.
n
Thanks Gary, hope the coffee does you good! Looking forward to someone else or a more caffeinated you!
@garyaustin It actually is working completely according to plan when I initialize with the service role. Maybe I can only setAuth to the service role when the client is a service role in the first place? Eh. For now I can continue!
n
Thread was archived by @Nin. Anyone can send a message to unarchive it.