Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin): add user role management #4248

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion apps/tailwind-components/components/Navigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const mainButtons = computed(() =>
const subButtons = computed(() =>
props.navigation.slice(props.maximumButtonShown)
);
const active = "underline";
chinook25 marked this conversation as resolved.
Show resolved Hide resolved
</script>

<template>
Expand Down
8 changes: 4 additions & 4 deletions apps/tailwind-components/server/routes/[schema]/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { joinURL } from "ufo";
import { createConsola } from "consola";

export default defineEventHandler((event) => {
const config = useRuntimeConfig(event);
const logger = createConsola({ level: config.logLevel?? 3 });
const config = useRuntimeConfig(event);
const logger = createConsola({ level: config.logLevel ?? 3 });
logger.info("proxy schema gql request : ", event.path);
if (event.method === "POST") {
readBody(event).then((body) => {
if (body.query) {
logger.debug( body.query);
logger.debug(body.query);
}
if (body.variables) {
logger.debug(body.variables);
Expand All @@ -17,6 +17,6 @@ export default defineEventHandler((event) => {
}
const schema = getRouterParam(event, "schema") || "";
logger.info("to : ", joinURL(config.public.apiBase, schema, "graphql"));
const target = joinURL(config.public.apiBase, schema,"graphql");
const target = joinURL(config.public.apiBase, schema, "graphql");
return proxyRequest(event, target);
});
15 changes: 11 additions & 4 deletions apps/ui/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const config = useRuntimeConfig();
const route = useRoute();
const { data: session } = await useSession();
console.log("session form defaiult layout: ", session.value);
console.log("session form default layout: ", session.value);

const faviconHref = config.public.emx2Theme
? `/_nuxt-styles/img/${config.public.emx2Theme}.ico`
Expand All @@ -11,16 +11,18 @@ const faviconHref = config.public.emx2Theme
useHead({
htmlAttrs: {
"data-theme":
(route.query.theme as string) || config.public.emx2Theme || "",
(route.query.theme as string) ||
(config.public.emx2Theme as string) ||
"",
},
link: [{ rel: "icon", href: faviconHref }],
titleTemplate: (titleChunk) => {
if (titleChunk && config.public.siteTitle) {
return `${titleChunk} | ${config.public.siteTitle}`;
} else if (titleChunk) {
return titleChunk;
} else if (config.public.siteTitle) {
return config.public.siteTitle;
// } else if (config.public.siteTitle) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this commented out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to get rid of the ts error while I was looking a the file, will undo when making this draft a pr

// return config.public.siteTitle;
} else {
return "Emx2";
}
Expand Down Expand Up @@ -65,6 +67,11 @@ const navigation = computed(() => {
<Navigation :navigation="navigation" />
</template>
<template #account>
<HeaderButton
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why a separate button , is this part of the design ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still just fiddling... So no clue and don't care yet.

label="Admin"
icon="Database"
@click="navigateTo({ path: '/admin/' })"
/>
<HeaderButton
:label="isSignedIn ? 'Account' : 'Signin'"
icon="user"
Expand Down
14 changes: 7 additions & 7 deletions apps/ui/middleware/adminOnly.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default defineNuxtRouteMiddleware(async (to, from) => {
const {data: session} = await useSession();
const isAdmin = computed(() => session.value.email === "admin");
if (!isAdmin.value) {
return navigateTo('/login')
}
})
export default defineNuxtRouteMiddleware(async (_to, _from) => {
const { data: session } = await useSession();
const isAdmin = computed(() => session.value.email === "admin");
if (!isAdmin.value) {
return navigateTo("/login");
}
});
6 changes: 4 additions & 2 deletions apps/ui/pages/account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ async function signout() {
type="primary"
size="medium"
@click="signout"
>Sign out</Button
>
Sign out
</Button>
<Button
v-else
type="primary"
size="medium"
@click="navigateTo('/login')"
>Sign in</Button
>
Sign in
</Button>
</div>
chinook25 marked this conversation as resolved.
Show resolved Hide resolved

<div class="mt-3">{{ errorMsg }}</div>
Expand Down
45 changes: 45 additions & 0 deletions apps/ui/pages/admin.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<template>
<PageHeader title="Admin Tools" />
<Container class="flex flex-col items-center">
<ContentBlock class="w-full mt-3" title="User management">
<h2>User List</h2>
<Table>
<template #head>
<TableHeadRow>
<TableHead>name</TableHead>
<TableHead>description</TableHead>
</TableHeadRow>
</template>
<template #body>
<TableRow v-for="user in users">
<TableCell>{{ user.userName }}</TableCell>
<TableCell>{{ user }}</TableCell>
</TableRow>
</template>
</Table>
</ContentBlock>
</Container>
</template>

<script lang="ts">
import { request } from "graphql-request";
chinook25 marked this conversation as resolved.
Show resolved Hide resolved
definePageMeta({
middleware: "admin-only",
});

const users = ref<Record<string, any>[]>([]);
const userCount = ref(0);

getUsers();

async function getUsers() {
const result: any = await request(
"graphql",
`{_admin{users{email},userCount}}`
).catch((error) => {
console.log("Error loading users: ", error);
});
users.value = result?._admin?.users || [];
userCount.value = result?._admin?.userCount ?? 0;
}
chinook25 marked this conversation as resolved.
Show resolved Hide resolved
</script>
Loading