Guest User

Untitled

a guest
Jul 24th, 2019
84
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. loaduserinfo() {
  2.  
  3. axios.get(port + '/api/user/me', {
  4. headers: {
  5. Authorization: AuthorizationHead + localStorage.getItem('TOKEN_KEY')
  6. }
  7. }).then((response) => {
  8.  
  9. this.currentuserinfo = '';
  10. this.currentuserinfo = response.data;
  11.  
  12. }).catch((error) => {
  13.  
  14. if (error.response.data.status == 401) {
  15. this.getnewjwttoken()
  16. .then(response => {
  17. if (response == 200) {
  18. this.loaduserinfo();
  19. }
  20. })
  21. }
  22. else if (error.response.data.status == 500) {
  23. console.log('500 Error');
  24. }
  25. else {
  26. console.log(error.response.data.message);
  27. }
  28.  
  29. })
  30.  
  31. }
  32.  
  33.  
  34.  
  35.  
  36. getnewjwttoken() {
  37.  
  38. return new Promise((resolve, reject) => {
  39.  
  40. var payload = {
  41. "refreshToken": localStorage.getItem('REFRESH_TOKEN')
  42. };
  43.  
  44. axios.post(port + '/api/auth/refresh-token', payload, {
  45. }).then((response) => {
  46. localStorage.setItem("TOKEN_KEY", response.data.accessToken);
  47. resolve(200);
  48. }).catch((error) => {
  49. alert("Session has Expired Please Login Again");
  50. this.logout();
  51. })
  52.  
  53. })
  54. }
RAW Paste Data