Closed Moulali1995 closed 4 years ago
Yes, you can use many express middleware in the moleculer-web API gateway, as well.
I tried the middlewares but redis store is not working. At first i thought like middleware is not called then @AndreMaz told me that "express server is not needed you can directly call middlewares and use express-session with the help of middlewares no need to create and start the express server.". But when i'm trying to connect to redis it is not working and the cookie is not sent and session data is not stored but when the same is tried with express framework alone it is working.
Please create a repro repo with middlewares what you need and we will check it.
I've created a repo please check. https://github.com/Moulali1995/moleculerjs-redis-jwt-express-session.git
env variables in .env.tmpconfig
login API: JWT token is generated http://localhost:3000/auth/login
payload : { "username": "user1", "password": "admin" }
authentication API: using the above JWT token and sending it in cookie headers http://localhost:3000/api/user
unable to see any sort of session id generated in the redis cli monitor.why? In response there is no express session cookie passed generated by the middleware express-session when the same is tried in express framework it works .why?
It's not correct:
ctx.meta.$responseHeaders = { Cookie: `session_token=${data.key}` };
Please check how to set a cookie or use a lib to generate cookie string.
Thanks @icebob it worked by removing the express-session code and directly using set and get methods of redis-store and by using set-cookie method.
How can i implement sessions in moleculer js using express-session and redis store for saving the session data? Does express-session runs without express server in moleculer js?