Added user sign up and login.

This commit is contained in:
DebaucheryLibrarian
2021-03-13 04:26:24 +01:00
parent 99cfd3dc3f
commit 816529b0ca
42 changed files with 741 additions and 8 deletions

View File

@@ -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;