K
K
keyotor2021-09-04 18:50:19
JSON Web Token
keyotor, 2021-09-04 18:50:19

Why don't cookies come to the server via getServerSideProps next.js?

Please tell me why the server does not receive cookies through getServerSideProps, here is the code that is on the client:

export async function getServerSideProps() {
  const res = await axios.get("http://localhost:5000/api/auth", {withCredentials: true});
  const data = await res.data;
  return { props: { data } }
}

on the server i have a strategy that checks access jwt token
export class JwtStrategy extends PassportStrategy(Strategy, "jwt") {
    constructor() {
        super({
            ignoreExpiration: false,
            secretOrKey: "secret",
            jwtFromRequest: ExtractJwt.fromExtractors([
                (request: Request) => {
                    console.log(request.cookies) // [Object: null prototype] {}
                    let data = request.cookies['access'];
                    return data;
                }
            ]),
        });
    }

    async validate(payload: any){
        return payload;
    }
}

That is, when I send a request through getServerSideProps, cookies do not come to the server, although if I send, for example, through useEffect, then cookies come normally

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question