Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import axios from 'axios'
- import React from 'react';
- import { Redirect } from "react-router-dom";
- import {AUTH_USER_REQUEST, AUTH_USER_SUCCESS, AUTH_USER_FAILURE} from './authTypes'
- export const loginUsers = (email, pass, error, history) => {
- return (dispatch) => {
- dispatch(authUserRequest())
- axios
- .post('http://127.0.0.1:8000/token', {username: email, password:pass, error:error})
- .then(response => {
- // response.data is the users
- dispatch(authUserSuccess())
- const user = response.data
- dispatch(authUserSuccess(user))
- console.log(response)
- alert("Hello! I am an alert box!!");
- //return <Redirect to = {{ pathname: "/dashboard" }} />;
- history.push('/dashboard')
- })
- .catch(error => {
- dispatch(authUserFailure())
- console.log(error.response)
- // error.message is the error message
- dispatch(authUserFailure(error.response))
- })
- }
- }
- export const authUserRequest = () => {
- return{
- type: AUTH_USER_REQUEST
- }
- }
- export const authUserSuccess = (email, pass) => {
- return{
- type: AUTH_USER_SUCCESS,
- payload: {email, pass}
- }
- }
- export const authUserFailure = error => {
- return{
- type: AUTH_USER_FAILURE,
- payload: error
- }
- }
Add Comment
Please, Sign In to add comment