So i'm having a regular route and an /api endpoints (both are written using Astro), the problem im facing is I want to fetch /api/profile and it returns a json element if the user is authentificated im using cookies for auth because supabase.auth.getSession() doesn't return anything (idk if im doing this right), using fetch from within <script is:inline> tag works fine but I want to render Astro components and I don't think it's possible to do so dynamically with document.createElement ? I went with having a separate .ts file exporting a getData which returns the fetched data, the problem here is the cookies aren't saved so I can't really GET /api/profile because the user is not authentificated, any solutions ?
#Dynamically generating components from an array
4 messages · Page 1 of 1 (latest)
I can fix the problem by writing the astro components with vanilla js & html instead inside that page but it's kinda annoying tbh if there is no fix I think I should do that
so just some researching and I found I needed to supply fetch with credentials: 'same-origin' but still it doesn't work I guess because the auth call is done in <script>
somehow Astro.cookies have the cookies so anyway I set it in fetch and it works