PhantomCode
03/02/2022, 7:53 AMposts
table where RLS is enabled without policies. I'd like to handle all the authorization logic in my servless backend with NextJS. Now, I have an endpoint /create-post
. Only administrators should be able to create a post. Therefore I implemented the following logic. Let's assume a user with the role administrator
is logged in. As far as I realized, the session is stored in local storage.
1. Question: to make a POST
request to the endpoint, I need to send the JWT with the request, because on my server, I do not have access to it via cookies right?
ts
await axios.post('/api/create-post', {
headers: {
authorization: session?.access_token || '',
},
body: ...
})
2. Question: the session
object comes from supabase.auth.session()
where I can take the access token. Is this a good practice to call that function or is it redundant to supabase.auth.user()
?
3. Question: In my serverless function, I want to fetch the user from Supabase via const { user } = await supabase.auth.api.getUser(req.headers.authorization)
. I saw in a video that this step is necessary to establish a session: supabase.auth.session = () => ({ access_token: req.headers.authorization })
but it is hacky and not TS conform. Is the alternative and better solution to use the service_role
key due to the fact that this is not exposed to the public anyways?
I'm very grateful for answers, thanks guys!irrationaljared
03/02/2022, 2:06 PMgaryaustin
03/02/2022, 2:44 PMJaeden
03/02/2022, 3:25 PMowner
column.garyaustin
03/02/2022, 4:09 PMVanege
03/03/2022, 1:41 PMastronautical
03/03/2022, 1:47 PMtandyman
03/04/2022, 1:41 AMconst { data, error } = await supabase
.from('restaurants')
.insert([
{ name: val,
restaurant_categories: {
category: newCategory
}
},
],
{ upsert: true })
tandyman
03/04/2022, 1:41 AMtandyman
03/04/2022, 1:42 AMgaryaustin
03/04/2022, 1:56 AMtandyman
03/04/2022, 2:20 AMtandyman
03/04/2022, 2:20 AMtandyman
03/04/2022, 2:23 AMgaryaustin
03/04/2022, 2:39 AMPhantomCode
03/04/2022, 7:49 AMrisingryzen
03/06/2022, 3:04 AMrisingryzen
03/06/2022, 5:40 AMhotbelgo
03/06/2022, 7:01 AMSite URL
but I can't work out how to use it with the Additional Redirect URLs
in the auth settingshotbelgo
03/06/2022, 7:05 AMhttps://abc.netlify.app/?x=y
works, but https://localhost:3000/?x=y does nothotbelgo
03/06/2022, 7:06 AM*✿❀♡cynthii♡❀✿*
03/07/2022, 4:48 AMchipilov
03/07/2022, 7:34 AMv.naeimabadi
03/07/2022, 10:58 AMgaryaustin
03/07/2022, 2:02 PMMartin INDIE MAKERS
03/08/2022, 3:48 PMMartin INDIE MAKERS
03/08/2022, 3:48 PMimage/png - 2 bytes
Martin INDIE MAKERS
03/08/2022, 3:49 PMimage/png
Martin INDIE MAKERS
03/08/2022, 3:50 PMawait supabase
.storage
.from('images')
.upload(`${userId.value}/${file.name}`, blob, {
contentType: file.mimeType,
})
Martin INDIE MAKERS
03/08/2022, 4:06 PM