getSession Headers Type

I'm trying to access the user session from an endpoint in my express server:
app.post('/print_auth', async (req: Request, res: Response) => {
const session = await auth.api.getSession({
headers: req.headers,
});
console.log(session);
res.json({ success: true });
});
app.post('/print_auth', async (req: Request, res: Response) => {
const session = await auth.api.getSession({
headers: req.headers,
});
console.log(session);
res.json({ success: true });
});
However, the type that getSession expects for headers is Headers, but the type express gives me is IncomingHttpHeaders. How do I fix this?
Solution:
Update: I wasn't including credentials: true in my fetch call to hit the endpoint, after that it started working. For the typing, this worked: ``` app.post('/print_auth', async (req: Request, res: Response) => {...
Jump to solution
1 Reply
Solution
Arnav
Arnav4d ago
Update: I wasn't including credentials: true in my fetch call to hit the endpoint, after that it started working. For the typing, this worked:
app.post('/print_auth', async (req: Request, res: Response) => {
const session = await auth.api.getSession({
headers: new Headers(req.headers as Record<string, string>),
});
console.log(session);
res.json({ success: true });
});
app.post('/print_auth', async (req: Request, res: Response) => {
const session = await auth.api.getSession({
headers: new Headers(req.headers as Record<string, string>),
});
console.log(session);
res.json({ success: true });
});

Did you find this page helpful?