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