https://supertokens.com/ logo
Hi team I have a use case where I have
j

Jrapp

04/20/2023, 6:30 PM
Hi team, I have a use-case where I have two separate websites (lets call them Website1 and Website2) sharing the same SuperTokens Auth DB. I want to be able to take requests from the backend of Website2 and forward them to the backend of Website1. I thought that just forwarding the cookies and other request details would work, but it only seems to work half the time. The first time it will receive the call I expect, but the next call always results in a 304. This is the proxy function to forward to Website1 from Website2:
export async function proxy(req: NextApiRequest, res: NextApiResponse): Promise<{ statusCode, json }> {
    const response = await fetch(`${process.env.ROOT_URL}${req.url}`, {
        method: req.method,
        headers: {
            ...(req.headers as any)
        },
        redirect: 'follow',
    });
    ...
}
and this is the code using it:
async function index(req, res) {
    await superTokensNextWrapper(
        async (next) => {
            return await verifySession()(req, res, next);
        }, req, res
    );

    const response = await proxy(req, res);
    return res.status(response.statusCode).json(response.json);
}
I'm thinking the error may be coming from the refreshing of sessions but im unsure how to check and tell. It seems like root the question is: "What triggers a 304 response"?
Update: discovered that this is not so much related to SuperTokens, more just caching. On the responses that returned 304, the header
if-none-match
was present which essentially tells the server to check if the response has changed from the last request. Deleting that header from the request before proxying it fixes the issue