Answer the question
In order to leave comments, you need to log in
How to get session from server in vuejs?
I screwed up authentication using passportjs - vkontakte.
Front and Back are on different domains. After authenticating in the browser with a GET request from the server, I get all the information about the session. The question is how to transfer it to vue, and then store it in some localStorage? Need to send a post somehow? What's in the settings? If in the case of the policy of logins and passwords, then the login and password are transmitted in the POST request. What to send here?
When I ask to return the session from the front via axios, it says that it is not authorized. It is understandable how the server knows that I want to get the desired session
. Sessions are stored in Mongo. I take it you need to take it out? How?
Answer the question
In order to leave comments, you need to log in
I did in 2 variants
A) postMessage as an option, listen to events from a different window.
B) It is possible through one-time tokens:
1) send a request, get a link by which you need to open a window and a token, by which in the future you will check whether the user has passed authentication, the same token can be specified in the dp parameters when responding from the vk server
2) open a new window and through the loop you check window.closed, they wait for the window to close.
3) in the window, the user is authenticated and returns to the callback link, in which the data to receive the token should be returned, and your one-time token, the server should answer is window.close() , get all the necessary data from VK and save it in
4) the frontend cycle catches the change in the window state, and send a request with a token to the server, on the server you check the status of the authentication and create a session
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question