Guest User

Untitled

a guest
Jan 16th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. const userPool = new CognitoUserPool(cognitoConfig)
  2.  
  3. const authenticationData = {
  4. Username: this.username,
  5. Password: this.password
  6. }
  7.  
  8. const authenticationDetails = new AuthenticationDetails(authenticationData)
  9.  
  10. const userData = {
  11. Username: this.username,
  12. Pool: userPool
  13. }
  14. const user = new CognitoUser(userData)
  15. const self = this
  16.  
  17. user.authenticateUser(authenticationDetails, {
  18. onSuccess: result => {
  19. const token = result.getAccessToken().getJwtToken()
  20. console.log('token = ', token)
  21. self.$store.commit('user/SET_USERNAME', self.username)
  22. self.$router.push('/dashboard')
  23. },
  24. onFailure: err => {
  25. console.log('err = ', err)
  26. }
  27. })
  28.  
  29. const userPool = new CognitoUserPool(cognitoConfig)
  30. const userData = {
  31. Username: this.user.username,
  32. Pool: userPool
  33. }
  34.  
  35. console.log('userData = ', userData)
  36.  
  37. const user = new CognitoUser(userData)
  38. user.getUserAttributes((err, result) => {
  39. if (err) {
  40. console.log('getUserAttributes err = ', err)
  41. alert(err.message || JSON.stringify(err))
  42. return
  43. }
  44. for (let i = 0; i < result.length; i++) {
  45. console.log('attribute ' + result[i].getName() + ' has value ' + result[i].getValue())
  46. }
  47. })
Add Comment
Please, Sign In to add comment