Polymer / polymer-starter-kit

A starting point for Polymer apps
2.46k stars 660 forks source link

Best practices for login screen #1093

Open mercmobily opened 6 years ago

mercmobily commented 6 years ago

Hi people,

what are the best practices for adding a login screen in PSK in terms of PRPL? I already have the logic, the ajax etc. At the moment, I have the login page added just as another page. However, I have:

      <iron-selector selected="[[page]]" attr-for-selected="name" class="drawer-list" role="navigation">
        <template is="dom-if" if="[[userData.loggedIn]]">
          <a name="home" href="[[rootPath]]home">Home</a>
          <a name="view-jobs" href="[[rootPath]]view-jobs">View Jobs</a>
          ...
          <a name="logout" on-tap="_logout">Logout</a>
        </template>

        <template is="dom-if" if="[[!userData.loggedIn]]">
          <a name="login">Login</a>
        </template>

And then:

  _routePageChanged (page, loggedIn) {
    // If no page was found in the route data, page will be an empty string.
    // Default to 'home' in that case.
    this.page = loggedIn ? page || 'home' : 'login'
  }

However, <view-jobs> might have a record open. Even though the page is no longer visible as such, it's still "there". Even after logout, the page might get server push updates; or, a user could logout and log back in as a different user -- and see the "old" data in that page. I am not sure how iron-pages would deal with restamping things. Initial testing showed that it doesn't seem to change anything. The only sure way I have to reset the app to zero is to actually reload the whole page. However, that feels a little lame...

Ideas?

Merc.

spencerwmiles commented 6 years ago

https://stackoverflow.com/a/46105917

Hope that helps a little friend