Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. // Component Login pada React
  2.  
  3. input(obj)
  4. {
  5. var self = this;
  6. axios.post('http://localhost:3001/Login',
  7. {
  8. username: obj.username.value,
  9. password: obj.password.value
  10. // Mengirim username dan password ke back-end
  11. })
  12. .then((response) => {
  13. var serverres = response.data;
  14. if (serverres === 1)
  15. {
  16. // artinya sukses login
  17. // lalu redirect ke component Cart (code di bawah)
  18. }
  19. else if (serverres === -1)
  20. {
  21. self.setState({
  22. status: 'Username/Password yang Anda masukkan salah'
  23. })
  24. }
  25. // If-else di atas untuk action dari respon yg didapat dari back-end setelah login
  26. });
  27. }
  28.  
  29. //================================================================================
  30. // Component Cart pada React
  31.  
  32. componentDidMount = () =>
  33. {
  34. // var self = this;
  35. axios.get('http://localhost:3001/Cart', {
  36. withCredentials: true
  37. })
  38. .then((response) => {});
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement