{"size": 1199, "ext": "js", "max_stars_repo_path": "client-ui/src/store/auth.module.js", "max_stars_repo_name": "kostua16/UNC_2020_MS_TLT", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client-ui/src/store/auth.module.js", "max_issues_repo_name": "kostua16/UNC_2020_MS_TLT", "max_issues_repo_issues_event_min_datetime": "2021-02-27T09:59:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T22:08:31.000Z", "max_forks_repo_path": "client-ui/src/store/auth.module.js", "max_forks_repo_name": "kostua16/UNC_2020_MS_TLT", "max_forks_repo_forks_event_min_datetime": "2021-03-03T15:43:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-22T10:30:46.000Z"}
{"max_stars_count": null, "max_issues_count": 471, "max_forks_count": 2, "avg_line_length": 25.5106382979, "max_line_length": 54, "alphanum_fraction": 0.4787322769}
import AuthService from '@/services/auth/auth-service'

const user = JSON.parse(localStorage.getItem('user'));
const initialState = user
    ? {status: {loggedIn: true}, user}
    : {status: {loggedIn: false}, user: null};

const auth = {
    namespaced: true,
    state: initialState,
    mutations: {
        LOGIN_SUCCESS(state, user) {
            state.status.loggedIn = true;
            state.user = user;
        },
        LOGIN_FAILURE(state) {
            state.status.loggedIn = false;
            state.user = null;
        },
        LOGOUT(state) {
            state.status.loggedIn = false;
            state.user = null;
        },
    },

    actions: {
        LOGIN({commit}, user) {
            return AuthService.login(user).then(
                user => {
                    commit('LOGIN_SUCCESS', user);
                    return Promise.resolve(user);
                },
                error => {
                    commit('LOGIN_FAILURE');
                    return Promise.reject(error);
                }
            );
        },

        LOGOUT({commit}) {
            AuthService.logout();
            commit('LOGOUT');
        },
    },
};

export default auth;