forked from DebaucheryLibrarian/traxxx
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;
|
||||
|
||||
@@ -1 +1,7 @@
|
||||
export default {};
|
||||
function setUser(state, user) {
|
||||
state.user = user;
|
||||
}
|
||||
|
||||
export default {
|
||||
setUser,
|
||||
};
|
||||
|
||||
5
assets/js/auth/observers.js
Normal file
5
assets/js/auth/observers.js
Normal file
@@ -0,0 +1,5 @@
|
||||
async function initAuthObserver(store, _router) {
|
||||
await store.dispatch('fetchMe');
|
||||
}
|
||||
|
||||
export default initAuthObserver;
|
||||
@@ -1,4 +1,3 @@
|
||||
export default {
|
||||
authenticated: false,
|
||||
user: null,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user