Questions & Answers

How can I handle cookies?

Deepkit HTTP
50 up-votes
Warning: The answer is generated by an artificial intelligence. It might not be correct.
To adjust rating, open the thread in Discord and click on the up/down vote button.

To handle cookies in Deepkit, you can use the @deepkit/http package. The HttpRequest object has a cookies property that allows you to access and manipulate cookies. You can use the setCookie method to set a new cookie and the getCookie method to retrieve a cookie by its name. Here is an example:

import { HttpMiddleware, HttpRequest, HttpResponse } from '@deepkit/http';

class CookieMiddleware implements HttpMiddleware {
    execute(request: HttpRequest, response: HttpResponse, next: (err?: any) => void) {
        // Set a cookie
        response.setCookie('myCookie', 'value', { maxAge: 3600, secure: true });

        // Get a cookie
        const myCookie = request.cookies.getCookie('myCookie');

        next();
    }
}