Headet token
This commit is contained in:
@@ -32,7 +32,6 @@ export default function Login() {
|
||||
const navigate = useNavigate();
|
||||
const userApi = new usersService();
|
||||
const doLogin = async () => {
|
||||
// userApi.getUserReminders(); test
|
||||
if (email !== "" && password !== "") {
|
||||
var postData = {
|
||||
username: email,
|
||||
@@ -40,9 +39,11 @@ export default function Login() {
|
||||
};
|
||||
const loginResult = await userApi.logInUser(postData); // just for a test
|
||||
// if (email === "support@mermsemr.com") {
|
||||
if (loginResult.data.status > 0) { // just for a start
|
||||
if (loginResult.data.status > 0 && loginResult.data.session_token !='') { // just for a start
|
||||
localStorage.setItem("email", `${email}`);
|
||||
localStorage.setItem("session_token", `${loginResult.data.session_token}`);
|
||||
setLoginLoading(true);
|
||||
// userApi.getUserReminders(); testing
|
||||
setTimeout(() => {
|
||||
toast.success("Login Successfully");
|
||||
navigate("/", { replace: true });
|
||||
|
||||
@@ -11,6 +11,7 @@ class usersService {
|
||||
/*
|
||||
clean up the request data here
|
||||
*/
|
||||
localStorage.setItem("session_token", ``);
|
||||
return this.postAuxEnd("/login", reqData);
|
||||
}
|
||||
|
||||
@@ -24,8 +25,16 @@ class usersService {
|
||||
//---------------------------------------- -----
|
||||
getAuxEnd(uri, reqData) {
|
||||
debugger;
|
||||
const session_token = localStorage.getItem("session_token");
|
||||
let axiosConfig = {
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
'Authorization': `Basic ${session_token}`,
|
||||
}
|
||||
};
|
||||
const endPoint = process.env.REACT_APP_USERS_ENDPOINT + uri;
|
||||
return Axios.get(endPoint)
|
||||
return Axios.get(endPoint,axiosConfig)
|
||||
.then((response) => {
|
||||
// console.log(response);
|
||||
// res = response;
|
||||
@@ -48,13 +57,12 @@ class usersService {
|
||||
|
||||
postAuxEnd(uri, reqData) {
|
||||
const endPoint = process.env.REACT_APP_USERS_ENDPOINT + uri;
|
||||
const token = '..your token..'
|
||||
const session_token = localStorage.getItem("session_token");
|
||||
let axiosConfig = {
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
'Authorization': `Basic ${token}`,
|
||||
'Authorization': `Basic ${session_token}`,
|
||||
}
|
||||
};
|
||||
//Access-Control-Allow-Origin
|
||||
@@ -64,7 +72,7 @@ class usersService {
|
||||
};
|
||||
// Axios.defaults.headers.post['Content-Type'] ='application/json;charset=utf-8';
|
||||
// Axios.defaults.headers.post['Access-Control-Allow-Origin'] = '*'; //,axiosConfig
|
||||
return Axios.post(endPoint, reqData)
|
||||
return Axios.post(endPoint, reqData,axiosConfig)
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
// res = response;
|
||||
|
||||
Reference in New Issue
Block a user