Is it possible to make requests "as" a particular user on the server? #1094
-
For context, I'm using Next.js with supabase-js, roughly following the Next.js with supabase auth example. I have a policy I know it'll work if I use the So, my question is: is it possible to "force" supabase-js to make requests as a certain user on the server? I can already get the user from the cookie using |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 25 replies
-
Check out #1067 Can the access token be used on the server? I'm curious, following this too |
Beta Was this translation helpful? Give feedback.
-
Hi @churichard, yes you can do that. You need to generate a JWT with the const supabase = createClient(supabaseUrl, supabaseKey, {
headers: {
apiKey: anonKey,
Authorisation: `Bearer ${jwt}`
}
}); |
Beta Was this translation helpful? Give feedback.
-
If using typescript you'll also need to set
|
Beta Was this translation helpful? Give feedback.
-
Follow up for Supabase JS
|
Beta Was this translation helpful? Give feedback.
Hi @churichard, yes you can do that. You need to generate a JWT with the
sub
claim as the user id and sign the JWT with your JWT secret of your project. Then you can pass that jwt into supabase-js like this.