A
A
Alexander2021-07-28 20:58:29
Node.js
Alexander, 2021-07-28 20:58:29

How to redirect after setting cookies in NextJS?

Hello, please tell me how to set cookies and make a redirect on the Next server?
Am I doing it right? I will be grateful for the answer

const token = jwt.sign(
            { userId: user.userId, username: user.username, email: user.email },
            process.env.JWT_SECRET,
            {
              expiresIn: '30 days',
            }
          )
          res.setHeader('Set-Cookie', serialize('token', token, { path: '/' }))
          res.redirect(307, `/activate/${hash}`)
          res.end();

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