Process it in the backend. If you do this with rails, be sure to use and abuse current_user, because it will be your best friend.
Then, in partial, you can have something like this
<% if current_user %>
<p>Welcome <%= current_user.username %>!</p>
<% else %>
<p>Please <%= link_to 'sign in', login_path %></p>
<% end %>
Rails, Ruby on Rails