Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //===================ACTION CREATOR=====================//
- import axios from 'axios';
- import {
- USER_LOGIN_SUCCESS,
- USER_NOT_FOUND,
- LOGIN_SYSTEM_ERROR,
- LOGIN_LOADING,
- REGISTER_LOADING,
- LOGOUT
- } from './types';
- export const onUserRegister = ({ username, email, phone, password }) => {
- return ( dispatch ) => {
- //=============INSERT USERNAME & PASSWORD KE JSON==============//
- dispatch({ type: REGISTER_LOADING });
- axios.post('http://localhost:1988/users', {
- username: username,
- email: email,
- phone: phone,
- password: password
- })
- .then((res) => {
- console.log(res);
- })
- .catch((err) => {
- console.log(err);
- })
- }
- }
- export const onUserLogout = () => {
- return { type: LOGOUT }
- }
- export const onUserLogin = ({ username, password }) => {
- return ( dispatch ) => {
- //=============VALIDASI USERNAME & PASSWORD KE JSON==============//
- dispatch({ type: LOGIN_LOADING });
- axios.get('http://localhost:1988/users', {
- params: {
- username: username,
- password: password
- }
- })
- .then((res) => {
- console.log(res);
- if(res.data.length > 0) {
- dispatch({ type: USER_LOGIN_SUCCESS, payload: username });
- } else {
- dispatch({ type: USER_NOT_FOUND });
- }
- })
- .catch((err) => {
- console.log(err);
- dispatch({ type: LOGIN_SYSTEM_ERROR });
- })
- }
- }
- export const keepLogin = (username) => {
- return { type: USER_LOGIN_SUCCESS, payload: username }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement