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