daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest Jun 17th, 2017 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Retrieve email/password object from the login/signup page
  2. function getCredentials() {
  3.   const user = {
  4.     email: document.querySelector('[name="email"]').value,
  5.     password: document.querySelector('[name="password"]').value
  6.   };
  7.  
  8.   return user;
  9. }
  10.  
  11. // Log in either using the given email/password or the token from storage
  12. function login(credentials) {
  13.   const payload = credentials ?
  14.     Object.assign({ strategy: 'local' }, credentials) : {};
  15.  
  16.   return client.authenticate(payload)
  17.     .then(showChat)
  18.     .catch(showLogin);
  19. }
  20.  
  21. document.addEventListener('click', function(ev) {
  22.   switch(ev.target.id) {
  23.     case 'signup': {
  24.       const user = getCredentials();
  25.  
  26.       // For signup, create a new user and then log them in
  27.       client.service('users').create(user)
  28.         .then(() => login(user));
  29.  
  30.       break;
  31.     }
  32.     case 'login': {
  33.       const user = getCredentials();
  34.  
  35.       login(user);
  36.  
  37.       break;
  38.     }
  39.     case 'logout': {
  40.       client.logout().then(() => {
  41.          document.getElementById('app').innerHTML = loginHTML;
  42.       });
  43.  
  44.       break;
  45.     }
  46.   }
  47. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top