From f0439dba40834f7e1663e6731ec0fa8fc7794e80 Mon Sep 17 00:00:00 2001 From: Davor Date: Wed, 18 May 2022 22:06:41 +0200 Subject: [PATCH] if user don't have new app_roles redirect to login - fix app preview --- src/App.tsx | 6 ++++-- src/modules/users/components/UserModal/consts.ts | 4 ++-- src/services/auth/redux/selectors.ts | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 0f7b653..d556ce1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -10,7 +10,9 @@ import { LoginCallback } from './modules/login/LoginCallback'; // eslint-disable-next-line @typescript-eslint/no-unused-vars function App() { - const { authToken } = useAuth(); + const { authToken, currentUser } = useAuth(); + + const redirectToLogin = !authToken || !currentUser?.app_roles; return ( <> @@ -26,7 +28,7 @@ function App() {
- {!authToken ? ( + {redirectToLogin ? ( } /> } /> diff --git a/src/modules/users/components/UserModal/consts.ts b/src/modules/users/components/UserModal/consts.ts index abda708..a47d6de 100644 --- a/src/modules/users/components/UserModal/consts.ts +++ b/src/modules/users/components/UserModal/consts.ts @@ -12,7 +12,7 @@ export const appAccessList = [ label: 'Wordpress', }, { - name: 'next-cloud', + name: 'nextcloud', image: '/assets/nextcloud.svg', label: 'NextCloud', }, @@ -37,7 +37,7 @@ const initialAppRoles = [ role: UserRole.User, }, { - name: 'next-cloud', + name: 'nextcloud', role: UserRole.User, }, { diff --git a/src/services/auth/redux/selectors.ts b/src/services/auth/redux/selectors.ts index c7ee882..0feaae5 100644 --- a/src/services/auth/redux/selectors.ts +++ b/src/services/auth/redux/selectors.ts @@ -12,6 +12,9 @@ export const getCurrentUser = (state: State) => state.auth.userInfo; export const getIsAdmin = (state: State) => { // check since old users wont have this if (state.auth.userInfo) { + if (!state.auth.userInfo.app_roles) { + return false; + } const isAdmin = state.auth.userInfo.app_roles.find( (role) => role.name === 'dashboard' && role.role === UserRole.Admin, );