Hangar/frontend/store/auth.ts

25 lines
743 B
TypeScript
Raw Normal View History

2021-01-31 10:00:11 +08:00
import { MutationTree } from 'vuex';
2021-02-09 02:26:18 +08:00
import { HangarUser } from 'hangar-internal';
2021-01-21 11:36:18 +08:00
export const state = () => ({
authenticated: false,
2021-02-09 02:26:18 +08:00
user: null as HangarUser | null,
2021-02-03 07:47:15 +08:00
token: null as string | null,
2021-02-05 08:22:22 +08:00
routePermissions: null as string | null,
2021-01-21 11:36:18 +08:00
});
export type AuthState = ReturnType<typeof state>;
export const mutations: MutationTree<AuthState> = {
2021-02-09 02:26:18 +08:00
SET_USER: (state: AuthState, user: HangarUser) => {
2021-02-03 07:47:15 +08:00
state.user = user;
},
2021-02-05 08:22:22 +08:00
SET_AUTHED: (state: AuthState, auth: boolean) => (state.authenticated = auth),
SET_TOKEN: (state: AuthState, token: string) => {
2021-02-03 07:47:15 +08:00
state.token = token;
},
2021-02-05 08:22:22 +08:00
SET_ROUTE_PERMISSIONS: (state: AuthState, perms: string) => {
state.routePermissions = perms;
},
2021-01-21 11:36:18 +08:00
};