diff --git a/src/actions/index.js b/src/actions/index.js index cbc73e8..1fe93f5 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -17,3 +17,15 @@ export const fetchUserProfile = (user) => async (dispatch) => { const response = { ...profile.data, ...test } dispatch({ type: 'FETCH_USER', payload: response }) }; + +export const userLogin = (username, password) => async (dispatch) => { + const response = await sudoscientist.post('/auth/signin', { + username: username, + password: password + }).then(function (response) { + console.log(response); + }).catch(function (error) { + console.log(error); + }); + console.log(response) +}; diff --git a/src/apis/sudoscientist.js b/src/apis/sudoscientist.js index 0def05f..2fc7103 100644 --- a/src/apis/sudoscientist.js +++ b/src/apis/sudoscientist.js @@ -1,5 +1,5 @@ import axios from 'axios'; export default axios.create({ - baseURL: 'https://api.sudoscientist.com/v1/api/' + baseURL: 'http://localhost:8080/v1/api/' }); diff --git a/src/components/AuthMenu.js b/src/components/AuthMenu.js index 1639fe1..389fd95 100644 --- a/src/components/AuthMenu.js +++ b/src/components/AuthMenu.js @@ -1,10 +1,13 @@ import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { userLogin } from '../actions'; class AuthMenu extends Component { constructor (props) { super(props) this.state = { + user_authed: false, where_in_auth_menu: "requestUsername", username: "", password: "", @@ -58,10 +61,7 @@ class AuthMenu extends Component { } handleLogin() { - this.setState(state => ({ - where_in_auth_menu: "requestPasswordForCreation", - auth_menu_visible: true, - })); + this.props.userLogin(this.state.username, this.state.password) } handleCreateAccount() { @@ -157,4 +157,12 @@ class AuthMenu extends Component { } } -export default (AuthMenu) +const mapStateToProps = (state) => { + return { + username: state.username, + }; +} +export default connect( + mapStateToProps, + { userLogin } +)(AuthMenu);