if user don't have new app_roles redirect to login

- fix app preview
This commit is contained in:
Davor 2022-05-18 22:06:41 +02:00
parent 79ec69a8f2
commit f0439dba40
3 changed files with 9 additions and 4 deletions

View file

@ -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() {
</Helmet>
<div className="app bg-gray-50 min-h-screen flex flex-col">
{!authToken ? (
{redirectToLogin ? (
<Routes>
<Route path="/login" element={<Login />} />
<Route path="/login-callback" element={<LoginCallback />} />

View file

@ -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,
},
{

View file

@ -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,
);