Hastic standalone https://hastic.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

36 lines
751 B

import { User } from "@/types/user";
import axios from 'axios';
// TODO: get it from config
const API_URL = '/api/auth/';
class AuthService {
login(user: User) {
return axios
.post(API_URL + 'signin', {
username: user.username,
password: user.password
})
.then((response: any) => {
if (response.data.accessToken) {
localStorage.setItem('user', JSON.stringify(response.data));
}
return response.data;
});
}
logout() {
localStorage.removeItem('user');
}
register(user: User) {
return axios.post(API_URL + 'signup', {
username: user.username,
email: user.email,
password: user.password
});
}
}
export default new AuthService();