Added user sign up and login.
This commit is contained in:
@@ -1,3 +1,42 @@
|
||||
function initAuthActions(_store, _router) {}
|
||||
import { get, post, del } from '../api';
|
||||
|
||||
function initAuthActions(_store, _router) {
|
||||
async function fetchMe({ commit }) {
|
||||
const user = await get('/session');
|
||||
|
||||
commit('setUser', user);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
async function login({ commit }, credentials) {
|
||||
const user = await post('/session', credentials);
|
||||
|
||||
commit('setUser', user);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
async function signup({ commit }, credentials) {
|
||||
const user = await post('/users', credentials);
|
||||
|
||||
commit('setUser', user);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
async function logout({ commit }) {
|
||||
await del('/session');
|
||||
|
||||
commit('setUser', null);
|
||||
}
|
||||
|
||||
return {
|
||||
fetchMe,
|
||||
login,
|
||||
logout,
|
||||
signup,
|
||||
};
|
||||
}
|
||||
|
||||
export default initAuthActions;
|
||||
|
||||
Reference in New Issue
Block a user