Advertisement
Guest User

Untitled

a guest
Jun 4th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import authentication from 'feathers-authentication-client'
  3. import {feathersClient} from './index'
  4.  
  5. feathersClient.configure(authentication({ storage: window.localStorage }))
  6.  
  7. const authenticate = async (email=null, password=null) => {
  8.     try {
  9.         let response
  10.         if(email && password) {
  11.             response = await feathersClient.authenticate({
  12.                 strategy: 'local',
  13.                 email,
  14.                 password
  15.             })
  16.         } else {
  17.             response = await feathersClient.authenticate()
  18.         }
  19.         const payload = await feathersClient.passport.verifyJWT(response.accessToken)
  20.         const user = await feathersClient.service('users').get(payload.userId)
  21.         feathersClient.set('user', user)
  22.         console.log(user)
  23.         return feathersClient.get('user')
  24.     }
  25.     catch(error) {
  26.         throw error
  27.     }
  28. }
  29.  
  30. const logout = () => {
  31.     return feathersClient.logout()
  32. }
  33.  
  34. export {
  35.     authenticate,
  36.     logout
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement