refs #5655 useRole and useUserConfig independents
gitea/salix-front/pipeline/head There was a failure building this commit
Details
gitea/salix-front/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
c4f40fbb59
commit
e254a1e721
|
@ -1,5 +1,4 @@
|
||||||
import { useState } from './useState';
|
import { useState } from './useState';
|
||||||
import { useUserConfig } from './useUserConfig';
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
export function useRole() {
|
export function useRole() {
|
||||||
|
@ -7,7 +6,6 @@ export function useRole() {
|
||||||
|
|
||||||
async function fetch() {
|
async function fetch() {
|
||||||
const { data } = await axios.get('VnUsers/acl');
|
const { data } = await axios.get('VnUsers/acl');
|
||||||
const userConfig = await useUserConfig().fetch();
|
|
||||||
const roles = data.roles.map((userRoles) => userRoles.role.name);
|
const roles = data.roles.map((userRoles) => userRoles.role.name);
|
||||||
|
|
||||||
const userData = {
|
const userData = {
|
||||||
|
@ -15,7 +13,6 @@ export function useRole() {
|
||||||
name: data.user.name,
|
name: data.user.name,
|
||||||
nickname: data.user.nickname,
|
nickname: data.user.nickname,
|
||||||
lang: data.user.lang || 'es',
|
lang: data.user.lang || 'es',
|
||||||
darkMode: userConfig.darkMode,
|
|
||||||
};
|
};
|
||||||
state.setUser(userData);
|
state.setUser(userData);
|
||||||
state.setRoles(roles);
|
state.setRoles(roles);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { useState } from './useState';
|
import { useState } from './useState';
|
||||||
import { useRole } from './useRole';
|
import { useRole } from './useRole';
|
||||||
|
import { useUserConfig } from './useUserConfig';
|
||||||
|
|
||||||
|
|
||||||
export function useSession() {
|
export function useSession() {
|
||||||
function getToken() {
|
function getToken() {
|
||||||
|
@ -36,11 +38,10 @@ export function useSession() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function login(token, keepLogin) {
|
async function login(token, keepLogin) {
|
||||||
const { fetch } = useRole();
|
|
||||||
|
|
||||||
setToken({ token, keepLogin });
|
setToken({ token, keepLogin });
|
||||||
|
|
||||||
await fetch();
|
await useRole().fetch();
|
||||||
|
await useUserConfig().fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
function isLoggedIn() {
|
function isLoggedIn() {
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import { useState } from './useState';
|
||||||
|
|
||||||
export function useUserConfig() {
|
export function useUserConfig() {
|
||||||
|
const state = useState();
|
||||||
|
|
||||||
async function fetch() {
|
async function fetch() {
|
||||||
const { data } = await axios.get('UserConfigs/getUserConfig');
|
const { data } = await axios.get('UserConfigs/getUserConfig');
|
||||||
return data;
|
const user = state.getUser().value;
|
||||||
|
user.darkMode = data.darkMode;
|
||||||
|
state.setUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue