Cookies 未设置。使用 AWS lambda、AWS API 网关(HTTP 而不是 REST)和 vercel

问题描述 投票:0回答:0

我正在发送

Set-Cookies
标头,但浏览器没有设置 cookies。

后端代码(Lambda):

import { verifyToken, createToken } from "/opt/auth.mjs";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import {
    DynamoDBDocumentClient,
    PutCommand,
    GetCommand,
    DeleteCommand,
    UpdateCommand,
} from "@aws-sdk/lib-dynamodb";

const client = new DynamoDBClient({});
const dynamo = DynamoDBDocumentClient.from(client);
export const handler = async (event) => {
    let body= "hello World"
    let statusCode = 200;
    const multiValueHeaders = {
        "Content-Type": "application/json",
        "Set-Cookie": [
            'isLoggedin=true',
            ],
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Headers': '*'
    };
    return {
        body,
        multiValueHeaders,
        statusCode,
    };
};

前端获取(Next.js 托管在 Vercel 上):

const response = await fetch(url, {
            method: "GET",
            headers: {
                "Content-Type": "application/json",
            },
        });

我尝试过的:

  • multivalueheaders(就 chrome webtools 可以显示的而言,从未接收过标头)
  • 普通标头(发送标头但浏览器不保存它)
amazon-web-services next.js aws-lambda aws-api-gateway
© www.soinside.com 2019 - 2024. All rights reserved.