Setting Cookies in API Route with `aws-lambda-streaming` nitro preset.

When trying to set a cookie in a SolidStart api route using vinxi/setCookie - nothing is being set. I'm just trying to figure out if this is a me issue or a possible nitro bug with the lambda streaming preset? Code is below - in the callback api route when I try to access the cookie using vinxi/getCookie I get 'undefined'.
import { sendRedirect, setCookie, getCookie } from "vinxi/http";
import { generateState } from "arctic";
import { github } from "@/lib/auth";

import type { APIEvent } from "@solidjs/start/server";

export async function GET(event: APIEvent) {
const state = generateState();
const url = github.createAuthorizationURL(state);
url.addScopes("read:user", "user:email");

setCookie(event.nativeEvent, "github_oauth_state", state, {
path: "/",
secure: true,
httpOnly: true,
maxAge: 60 * 10,
sameSite: "lax"
});

return sendRedirect(event.nativeEvent, url.toString());
}
import { sendRedirect, setCookie, getCookie } from "vinxi/http";
import { generateState } from "arctic";
import { github } from "@/lib/auth";

import type { APIEvent } from "@solidjs/start/server";

export async function GET(event: APIEvent) {
const state = generateState();
const url = github.createAuthorizationURL(state);
url.addScopes("read:user", "user:email");

setCookie(event.nativeEvent, "github_oauth_state", state, {
path: "/",
secure: true,
httpOnly: true,
maxAge: 60 * 10,
sameSite: "lax"
});

return sendRedirect(event.nativeEvent, url.toString());
}
1 Reply
Madaxen86
Madaxen864mo ago
If you are working on localhost you get undefined because you don’t have a https connection which is necessary if you set the config to secure:true which you need in production obviously. So you could set secure: import.meta.env.PROD
Want results from more Discord servers?
Add your server