mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Merge pull request #721 from directus/no-role-user-login
Fix login in with user with no role
This commit is contained in:
@@ -49,7 +49,7 @@ router.get(
|
||||
router.get(
|
||||
'/me',
|
||||
asyncHandler(async (req, res, next) => {
|
||||
if (!req.accountability?.user || !req.accountability?.role) {
|
||||
if (!req.accountability?.user) {
|
||||
throw new InvalidCredentialsException();
|
||||
}
|
||||
|
||||
|
||||
@@ -58,11 +58,21 @@ router.get(
|
||||
if (!req.accountability?.user) {
|
||||
throw new InvalidCredentialsException();
|
||||
}
|
||||
|
||||
const service = new UsersService({ accountability: req.accountability });
|
||||
|
||||
const item = await service.readByKey(req.accountability.user, req.sanitizedQuery);
|
||||
try {
|
||||
const item = await service.readByKey(req.accountability.user, req.sanitizedQuery);
|
||||
res.locals.payload = { data: item || null };
|
||||
} catch (error) {
|
||||
if (error instanceof ForbiddenException) {
|
||||
res.locals.payload = { data: { id: req.accountability.user } };
|
||||
return next();
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
res.locals.payload = { data: item || null };
|
||||
return next();
|
||||
}),
|
||||
respond
|
||||
|
||||
@@ -14,15 +14,7 @@
|
||||
</template>
|
||||
</v-info>
|
||||
|
||||
<router-view v-else-if="!hydrating && appAccess" />
|
||||
|
||||
<v-info v-else-if="appAccess === false" center :title="$t('no_app_access')" type="danger" icon="block">
|
||||
{{ $t('no_app_access_copy') }}
|
||||
|
||||
<template #append>
|
||||
<v-button to="/logout">Switch User</v-button>
|
||||
</template>
|
||||
</v-info>
|
||||
<router-view v-else-if="!hydrating" />
|
||||
|
||||
<portal-target name="dialog-outlet" transition="transition-dialog" multiple />
|
||||
<portal-target name="menu-outlet" transition="transition-bounce" multiple />
|
||||
@@ -88,7 +80,7 @@ export default defineComponent({
|
||||
document.body.classList.remove('light');
|
||||
document.body.classList.remove('auto');
|
||||
|
||||
if (newUser !== undefined && newUser !== null) {
|
||||
if (newUser !== undefined && newUser !== null && newUser.theme) {
|
||||
document.body.classList.add(newUser.theme);
|
||||
} else {
|
||||
// Default to light mode
|
||||
@@ -108,11 +100,6 @@ export default defineComponent({
|
||||
return settingsStore.state?.settings?.custom_css || '';
|
||||
});
|
||||
|
||||
const appAccess = computed(() => {
|
||||
if (!userStore.state.currentUser) return true;
|
||||
return userStore.state.currentUser?.role?.app_access || false;
|
||||
});
|
||||
|
||||
const error = computed(() => appStore.state.error);
|
||||
|
||||
/**
|
||||
@@ -124,7 +111,7 @@ export default defineComponent({
|
||||
axios,
|
||||
});
|
||||
|
||||
return { hydrating, brandStyle, appAccess, error, customCSS };
|
||||
return { hydrating, brandStyle, error, customCSS };
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -57,11 +57,11 @@ export async function hydrate(stores = useStores()) {
|
||||
*/
|
||||
await userStore.hydrate();
|
||||
|
||||
await setLanguage((userStore.state.currentUser?.language as Language) || 'en-US');
|
||||
|
||||
await Promise.all(stores.filter(({ id }) => id !== 'userStore').map((store) => store.hydrate?.()));
|
||||
|
||||
await registerModules();
|
||||
if (userStore.state.currentUser?.role) {
|
||||
await setLanguage((userStore.state.currentUser?.language as Language) || 'en-US');
|
||||
await Promise.all(stores.filter(({ id }) => id !== 'userStore').map((store) => store.hydrate?.()));
|
||||
await registerModules();
|
||||
}
|
||||
} catch (error) {
|
||||
appStore.state.error = error;
|
||||
} finally {
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<template>
|
||||
<div class="private-view" :class="{ theme }">
|
||||
<v-info v-if="appAccess === false" center :title="$t('no_app_access')" type="danger" icon="block">
|
||||
{{ $t('no_app_access_copy') }}
|
||||
|
||||
<template #append>
|
||||
<v-button to="/logout">Switch User</v-button>
|
||||
</template>
|
||||
</v-info>
|
||||
|
||||
<div v-else class="private-view" :class="{ theme }">
|
||||
<aside role="navigation" aria-label="Module Navigation" class="navigation" :class="{ 'is-open': navOpen }">
|
||||
<module-bar />
|
||||
<div class="module-nav alt-colors">
|
||||
@@ -81,6 +89,11 @@ export default defineComponent({
|
||||
const userStore = useUserStore();
|
||||
const appStore = useAppStore();
|
||||
|
||||
const appAccess = computed(() => {
|
||||
if (!userStore.state.currentUser) return true;
|
||||
return userStore.state.currentUser?.role?.app_access || false;
|
||||
});
|
||||
|
||||
const notificationsPreviewActive = ref(false);
|
||||
|
||||
const { sidebarOpen } = toRefs(appStore.state);
|
||||
@@ -98,6 +111,7 @@ export default defineComponent({
|
||||
sidebarOpen,
|
||||
openSidebar,
|
||||
notificationsPreviewActive,
|
||||
appAccess,
|
||||
};
|
||||
|
||||
function openSidebar(event: PointerEvent) {
|
||||
|
||||
Reference in New Issue
Block a user