to master
This commit is contained in:
@ -9,18 +9,23 @@ const headers = {
|
|||||||
if (token) headers["Authorization"] = `Bearer ${token}`;
|
if (token) headers["Authorization"] = `Bearer ${token}`;
|
||||||
|
|
||||||
const instance = axios.create({
|
const instance = axios.create({
|
||||||
baseURL: 'https://api.telkomcel.tl/tpay-stg-dash-api/',
|
baseURL: `http://127.0.0.1:4003`,
|
||||||
|
// baseURL: 'https://api.telkomcel.tl/tpay-stg-dash-api/',
|
||||||
headers: headers
|
headers: headers
|
||||||
})
|
})
|
||||||
|
|
||||||
export async function fetchApi(path, method, data, params) {
|
export async function fetchApi(path, method, data, params) {
|
||||||
let query = params || {};
|
try {
|
||||||
query.token = token
|
let query = params || {};
|
||||||
let response = await instance({
|
query.token = token
|
||||||
method: method,
|
let response = await instance({
|
||||||
url: path,
|
method: method,
|
||||||
data: data,
|
url: path,
|
||||||
params: query
|
data: data,
|
||||||
});
|
params: query
|
||||||
return response
|
});
|
||||||
|
return response
|
||||||
|
} catch (error) {
|
||||||
|
alert(error.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -18,25 +18,28 @@ const LoginPage = () => {
|
|||||||
if (username && password) {
|
if (username && password) {
|
||||||
// GET CREDIENTIAL
|
// GET CREDIENTIAL
|
||||||
let user = await fetchApi('/api/login', 'POST', { username, password });
|
let user = await fetchApi('/api/login', 'POST', { username, password });
|
||||||
if (user.data && user.data.data) {
|
if (user) {
|
||||||
let resUserLogin = user.data.data;
|
if (user.data && user.data.data) {
|
||||||
console.log('resUserLogin', resUserLogin);
|
let resUserLogin = user.data.data;
|
||||||
let roleList = JSON.stringify(resUserLogin.roles_list);
|
console.log('resUserLogin', resUserLogin);
|
||||||
Cookies.set('token', resUserLogin.token.access_token, { expires: 1, path: '/' });
|
let roleList = JSON.stringify(resUserLogin.roles_list);
|
||||||
Cookies.set('role', resUserLogin.role_name, { expires: 1, path: '/' });
|
Cookies.set('token', resUserLogin.token.access_token, { expires: 1, path: '/' });
|
||||||
Cookies.set('userId', resUserLogin.user.id, { expires: 1, path: '/' });
|
Cookies.set('role', resUserLogin.role_name, { expires: 1, path: '/' });
|
||||||
Cookies.set('username', resUserLogin.user.username, { expires: 1, path: '/' });
|
Cookies.set('userId', resUserLogin.user.id, { expires: 1, path: '/' });
|
||||||
// Cookies.set('roles_list', roleList, { expires: 1, path: '/' });
|
Cookies.set('username', resUserLogin.user.username, { expires: 1, path: '/' });
|
||||||
localStorage.setItem('roles_list', roleList)
|
// Cookies.set('roles_list', roleList, { expires: 1, path: '/' });
|
||||||
navigate('/');
|
localStorage.setItem('roles_list', roleList)
|
||||||
} else {
|
navigate('/');
|
||||||
alert(user.response.data.message);
|
} else {
|
||||||
|
alert(user.response.data.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
alert("Please fill in both fields.");
|
alert("Please fill in both fields.");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error.response.data.message);
|
if (error.response) alert(error.response.data.message)
|
||||||
|
else alert(error.message)
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -86,8 +86,7 @@ function App() {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(roles_list);
|
console.log(roles_list, location);
|
||||||
console.log(location);
|
|
||||||
|
|
||||||
}, [roles_list, location]);
|
}, [roles_list, location]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user