Git Product home page Git Product logo

Comments (4)

icyJoseph avatar icyJoseph commented on August 11, 2024 1

A bit tricky to see the issue in your example, because, straight up navigating to the landing page, sets a cookie too. That being said, I think something like this should work:

import { NextRequest, NextResponse } from "next/server";

export async function middleware(request: NextRequest) {
  const expires = new Date();
  expires.setMinutes(expires.getMinutes() + 60);

  const cookie = {
    httpOnly: true,
    name: "random_string",
    value: Math.random().toString(),
    expires,
  };

  request.cookies.set(cookie.name, cookie.value);

  let response = NextResponse.next({
    request: {
      headers: new Headers(request.headers),
    },
  });
  response.cookies.set(cookie);

  return response;
}

from next.js.

icyJoseph avatar icyJoseph commented on August 11, 2024 1

I mean, I put it together from information present in the docs.

That link documents how to forward modified headers.

And that it is mentioned that you can set cookies on the incoming request:

For incoming requests, cookies comes with the following methods: get, getAll, set, and delete cookies. You can check for the existence of a cookie with has or remove all cookies with clear.

On the same page as the link above.

from next.js.

viniciusbitt avatar viniciusbitt commented on August 11, 2024

@icyJoseph It's kind of difficult to reproduce, you have to simulate the "access_token" (random_string) cookie expiring when calling server action, that's why I said to clear the cookies in the first step.

I tested your example and it worked, but is it the right way to do this? Looks like I'm back to the issue #49442

from next.js.

Pbmangan avatar Pbmangan commented on August 11, 2024

I believe this issue is impacting supabase sever side auth on NextJS supabase/ssr#36

from next.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.