Answer the question
In order to leave comments, you need to log in
How to make authorization in node.js + socket.io chat on a site using PHP?
There is a php site to which I want to attach a chat, as the best option I chose a chat using sockets (node.js + socket.io), I seem to have done everything, but I don’t know how to implement user authorization in this chat using data account from php and database.
p.s. I'm using MongoDB
Answer the question
In order to leave comments, you need to log in
1) request a php script from the node, which will say whether the user is authorized. (easy way)
2) store the session (session token) in a common database, so that it is easy to know from the node if the user is authorized (good way)
3) Implement the same authorization method in the node as in php. (bad way - you have to re-request the password to enter the chat)
4) use Redis PubSub to exchange information between php and node. (bad way - in php you will have to constantly request data if there is a new request in the channel)
You can get smart with sessions in PHP. Move session storage from files to mongodb. Then both the node and PHP will work with shared session variables.
Or it's stupid to write a random auth_key during authorization from PHP to the database, and save it in cookies.
And in the node, get the auth_key cookie and look for it in the user database and, for example, check the login IP.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question