#combining auth-astro with api endpoints

3 messages · Page 1 of 1 (latest)

stark jackal
#

I was wondering if anybody tried auth authentication with astro's api-endpoints using auth-astro? I was hoping we could do something like

// pages/api/create.json.ts
import { getSession } from 'auth-astro/server';

export async function get({ params, request }) {
  const session = await getSession(request);
  return {
    ...
  };
}

and then fetch it like

// pages/index.astro
---
const response = await (
  await fetch('http://localhost:3030/api/projects/create.json', { credentials: 'same-origin' })
).json();
---

but then session is undefined in pages/api/create.json.ts.

gentle mantleBOT
#
Quiet in here?

It looks like no-one has responded to your question yet. People might not be available right now or don’t know how to answer your question. Want an answer while you wait? Try asking our experimental bot in #1095492539085230272.

stark jackal
#

Okay apparently I can do:

const response = await fetch('http://localhost:3030/api/create.json', { headers: Astro.request.headers  })

and then the appropriate cookies are passed on to the api-endpoint.