当用户未登录我的网站时,他在引用我<%=
代码所在的行时会抛出错误。
<% if(session.passport){ %>
<div class='picture flex flex-v flex-h'>
<img src='<%= session.passport.user.avatar %>'>
</div>
<div>
<div class='name'>
<%= session.passport.user.username %>
</div>
</div>
<div class='settings'>
<a href='/logout'>
<i class="fas fa-sign-out-alt"></i>
</a>
</div>
<% }else{ %>
<a style='height:100%;width:100%;' href='/auth/opskins'>
<div class='wrapper flex flex-v flex-h'>
<div class='login'></div>
<div>
<div><h2>Sign In</h2></div>
<div><h6>via OPSkins</h6></div>
</div>
</div>
</a>
<% } %>
但是,我确实检查用户是否已登录,但仍然得到session.passport.user
是undefined
(即使不应检查),我在这里看不到吗?>
错误:
Cannot read property 'avatar' of undefined