Commit c66ccc1a authored by Darrick Yong's avatar Darrick Yong

add session connection to frontend

parent 3c12209b
import * as SessionAPIUtil from "../util/session_api_util";
export const LOGIN_USER = 'LOGIN_USER';
export const LOGOUT_USER = 'LOGOUT_USER';
export const LOGIN_USER = "LOGIN_USER";
export const LOGOUT_USER = "LOGOUT_USER";
const receiveLogin = (user) => ({
type: LOGIN_USER,
user,
})
});
const receiveLogout = () => ({
type: LOGOUT_USER,
})
});
export const login = payload => dispatch => {
SessionAPIUtil.createSession(payload)
.then(res => {
dispatch(receiveLogin(res))
})
}
export const login = (payload) => (dispatch) => {
SessionAPIUtil.createSession(payload).then((res) => {
const { status, data } = res;
if (status < 299) {
dispatch(receiveLogin(data));
}
});
};
export const logout = () => dispatch => {
export const logout = () => (dispatch) => {
dispatch(receiveLogout());
}
};
// import axios from 'axios';
import axios from "axios";
export const createSession = (payload) => {
const { token, user } = payload;
// call axios with token
return new Promise((resolve, reject) => {
resolve(user);
})
return axios
.post("http://localhost:8080/api/auth", payload)
.catch((err) => err.response);
};
......@@ -7,8 +7,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "")
public class AuthenticationController {
@RequestMapping(value = "/api")
public class SessionController {
@Autowired
SessionService sessionService;
......
......@@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;
@Service
public class SessionService {
......@@ -29,8 +30,8 @@ public class SessionService {
.body(session);
}
return ResponseEntity
.status(HttpStatus.BAD_REQUEST)
.body(null);
.status(HttpStatus.UNAUTHORIZED)
.body(session);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment