@Somename:
The workflow which you have mentioned is slightly correct.
The ideal way to get passport authentication done is,
- User log's in entering his username and passport.
- Send a post request with these form data.
- Authenticate the credentials using Passport. Using the passport.authenticate will invoke the serializeUser and get you the valid user if it exists. Else we return a login error response.
- A Successful login will automatically create a session in back end, save it in the sessionStorage and adds it with the response.
- This cookie will be saved automatically into browser's local storage once the response is fetched at client side.
- Every time we send a subsequent API request we need to include this cookie in the req headers.
- This cookie should be validated each time in back end. passport.authorize will again make use of the cookie and check if the session is valid.
Logout session once the User logs out.
Hope I've made things clear for you.