Skip to content

Cookies #710

Answered by RobinTail
fabioziliani asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @fabioziliani ,

In order to manage (read and set) cookies, you might need to connect cookie-parser express middleware.
https://expressjs.com/en/api.html#req.cookies

You can achieve it by using .use() or .addExpressMiddleware() method of EndpointsFactory.

After that, request.cookies will be populated by the received cookies. In order to handle them (for authentication purposes) you can write a middleware like this:

const authMw = createMiddleware({
  input: z.object({}),
  middleware: async ({request, response}) => {
    const { cookies } = request; // here are your cookies
    // do something
    response.cookie('anotherOne', 'some value'); // send another cookie
    return { cookies }

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by RobinTail
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
good first issue Good for newcomers
2 participants