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;

View File

@@ -1 +1,7 @@
export default {};
function setUser(state, user) {
state.user = user;
}
export default {
setUser,
};

View File

@@ -0,0 +1,5 @@
async function initAuthObserver(store, _router) {
await store.dispatch('fetchMe');
}
export default initAuthObserver;

View File

@@ -1,4 +1,3 @@
export default {
authenticated: false,
user: null,
};