Вопрос

I'm using passportjs on my server for authentication, and I'm wondering if any value gets set on the client side that tells the client whether or not they are logged in. If not, how would you go about giving the client this information? Does the client have access to information about sessions?

  1. Different response headers, but sending same file on the server side, and then looking at the response header on the client side to set a "loggedIn" value.
  2. Sending a query after page load that checks whether or not the user is logged in, and then sets a value.
  3. Something else?

Thanks!

Это было полезно?

Решение

Generally speaking, in express/passport if req.user is set, then you may treat the user as logged in. To my knowledge, there isn't any specific response sent to the client across all implementations. What's typically done is a check against req.user and then different logic flows (say, rendering a different header). You can also render that data in your HTML preprocessor.

var isLoggedIn = !!req.user;
res.render('myPage', { loggedIn: isLoggedIn });
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top