Search code examples
v4l2loopback

How can I access the cookies on the sequence in Loopback 4?


How can I access the cookies on the sequence in Loopback 4 ? I need to validate a session that is sent in a cookie, how can I access its value in loopback 4?

Thanks a lot.


Solution

  • In your sequence file, you have your request like this:

    const {request, response} = context;
    

    You can then use request.headers.cookie to get your cookie. This is the simple answer.

    But to validate your session, I think it would be better to implement a middleware in your sequence and then do your authentication there. You can get some inspiration from there: https://github.com/strongloop/loopback-next/tree/master/packages/authentication