mirror of
https://github.com/kevin-DL/complete-node-bootcamp.git
synced 2026-01-20 06:35:11 +00:00
39 lines
905 B
JavaScript
39 lines
905 B
JavaScript
/* eslint-disable */
|
|
import axios from 'axios';
|
|
import { showAlert } from './alerts';
|
|
|
|
export const login = async (email, password) => {
|
|
try {
|
|
const res = await axios({
|
|
method: 'POST',
|
|
url: 'http://127.0.0.1:3000/api/v1/users/login',
|
|
data: {
|
|
email,
|
|
password
|
|
}
|
|
});
|
|
|
|
if (res.data.status === 'success') {
|
|
showAlert('success', 'Logged in successfully!');
|
|
window.setTimeout(() => {
|
|
location.assign('/');
|
|
}, 1500);
|
|
}
|
|
} catch (err) {
|
|
showAlert('error', err.response.data.message);
|
|
}
|
|
};
|
|
|
|
export const logout = async () => {
|
|
try {
|
|
const res = await axios({
|
|
method: 'GET',
|
|
url: 'http://127.0.0.1:3000/api/v1/users/logout'
|
|
});
|
|
if ((res.data.status = 'success')) location.reload(true);
|
|
} catch (err) {
|
|
console.log(err.response);
|
|
showAlert('error', 'Error logging out! Try again.');
|
|
}
|
|
};
|