refactor: update roles

This commit is contained in:
Mauricio Siu
2025-02-15 19:23:08 -06:00
parent d233f2c764
commit 1c5cc5a0db
45 changed files with 141 additions and 132 deletions

View File

@@ -15,7 +15,7 @@ export const ShowWelcomeDokploy = () => {
const { data: isCloud, isLoading } = api.settings.isCloud.useQuery(); const { data: isCloud, isLoading } = api.settings.isCloud.useQuery();
if (!isCloud || data?.rol !== "admin") { if (!isCloud || data?.role !== "admin") {
return null; return null;
} }
@@ -24,14 +24,14 @@ export const ShowWelcomeDokploy = () => {
!isLoading && !isLoading &&
isCloud && isCloud &&
!localStorage.getItem("hasSeenCloudWelcomeModal") && !localStorage.getItem("hasSeenCloudWelcomeModal") &&
data?.rol === "admin" data?.role === "owner"
) { ) {
setOpen(true); setOpen(true);
} }
}, [isCloud, isLoading]); }, [isCloud, isLoading]);
const handleClose = (isOpen: boolean) => { const handleClose = (isOpen: boolean) => {
if (data?.rol === "admin") { if (data?.role === "owner") {
setOpen(isOpen); setOpen(isOpen);
if (!isOpen) { if (!isOpen) {
localStorage.setItem("hasSeenCloudWelcomeModal", "true"); // Establece el flag al cerrar el modal localStorage.setItem("hasSeenCloudWelcomeModal", "true"); // Establece el flag al cerrar el modal

View File

@@ -155,7 +155,7 @@ const MENU: Menu = {
// Only enabled for admins and users with access to Traefik files in non-cloud environments // Only enabled for admins and users with access to Traefik files in non-cloud environments
isEnabled: ({ auth, user, isCloud }) => isEnabled: ({ auth, user, isCloud }) =>
!!( !!(
(auth?.role === "admin" || user?.canAccessToTraefikFiles) && (auth?.role === "owner" || user?.canAccessToTraefikFiles) &&
!isCloud !isCloud
), ),
}, },
@@ -166,7 +166,7 @@ const MENU: Menu = {
icon: BlocksIcon, icon: BlocksIcon,
// Only enabled for admins and users with access to Docker in non-cloud environments // Only enabled for admins and users with access to Docker in non-cloud environments
isEnabled: ({ auth, user, isCloud }) => isEnabled: ({ auth, user, isCloud }) =>
!!((auth?.role === "admin" || user?.canAccessToDocker) && !isCloud), !!((auth?.role === "owner" || user?.canAccessToDocker) && !isCloud),
}, },
{ {
isSingle: true, isSingle: true,
@@ -175,7 +175,7 @@ const MENU: Menu = {
icon: PieChart, icon: PieChart,
// Only enabled for admins and users with access to Docker in non-cloud environments // Only enabled for admins and users with access to Docker in non-cloud environments
isEnabled: ({ auth, user, isCloud }) => isEnabled: ({ auth, user, isCloud }) =>
!!((auth?.role === "admin" || user?.canAccessToDocker) && !isCloud), !!((auth?.role === "owner" || user?.canAccessToDocker) && !isCloud),
}, },
{ {
isSingle: true, isSingle: true,
@@ -184,7 +184,7 @@ const MENU: Menu = {
icon: Forward, icon: Forward,
// Only enabled for admins and users with access to Docker in non-cloud environments // Only enabled for admins and users with access to Docker in non-cloud environments
isEnabled: ({ auth, user, isCloud }) => isEnabled: ({ auth, user, isCloud }) =>
!!((auth?.role === "admin" || user?.canAccessToDocker) && !isCloud), !!((auth?.role === "owner" || user?.canAccessToDocker) && !isCloud),
}, },
// Legacy unused menu, adjusted to the new structure // Legacy unused menu, adjusted to the new structure
@@ -252,7 +252,7 @@ const MENU: Menu = {
icon: Activity, icon: Activity,
// Only enabled for admins in non-cloud environments // Only enabled for admins in non-cloud environments
isEnabled: ({ auth, user, isCloud }) => isEnabled: ({ auth, user, isCloud }) =>
!!(auth?.role === "admin" && !isCloud), !!(auth?.role === "owner" && !isCloud),
}, },
{ {
isSingle: true, isSingle: true,
@@ -266,7 +266,7 @@ const MENU: Menu = {
url: "/dashboard/settings/servers", url: "/dashboard/settings/servers",
icon: Server, icon: Server,
// Only enabled for admins // Only enabled for admins
isEnabled: ({ auth, user, isCloud }) => !!(auth?.role === "admin"), isEnabled: ({ auth, user, isCloud }) => !!(auth?.role === "owner"),
}, },
{ {
isSingle: true, isSingle: true,
@@ -274,7 +274,7 @@ const MENU: Menu = {
icon: Users, icon: Users,
url: "/dashboard/settings/users", url: "/dashboard/settings/users",
// Only enabled for admins // Only enabled for admins
isEnabled: ({ auth, user, isCloud }) => !!(auth?.role === "admin"), isEnabled: ({ auth, user, isCloud }) => !!(auth?.role === "owner"),
}, },
{ {
isSingle: true, isSingle: true,
@@ -283,7 +283,7 @@ const MENU: Menu = {
url: "/dashboard/settings/ssh-keys", url: "/dashboard/settings/ssh-keys",
// Only enabled for admins and users with access to SSH keys // Only enabled for admins and users with access to SSH keys
isEnabled: ({ auth, user }) => isEnabled: ({ auth, user }) =>
!!(auth?.role === "admin" || user?.canAccessToSSHKeys), !!(auth?.role === "owner" || user?.canAccessToSSHKeys),
}, },
{ {
isSingle: true, isSingle: true,
@@ -292,7 +292,7 @@ const MENU: Menu = {
icon: GitBranch, icon: GitBranch,
// Only enabled for admins and users with access to Git providers // Only enabled for admins and users with access to Git providers
isEnabled: ({ auth, user }) => isEnabled: ({ auth, user }) =>
!!(auth?.role === "admin" || user?.canAccessToGitProviders), !!(auth?.role === "owner" || user?.canAccessToGitProviders),
}, },
{ {
isSingle: true, isSingle: true,
@@ -300,7 +300,7 @@ const MENU: Menu = {
url: "/dashboard/settings/registry", url: "/dashboard/settings/registry",
icon: Package, icon: Package,
// Only enabled for admins // Only enabled for admins
isEnabled: ({ auth, user, isCloud }) => !!(auth?.role === "admin"), isEnabled: ({ auth, user, isCloud }) => !!(auth?.role === "owner"),
}, },
{ {
isSingle: true, isSingle: true,
@@ -308,7 +308,7 @@ const MENU: Menu = {
url: "/dashboard/settings/destinations", url: "/dashboard/settings/destinations",
icon: Database, icon: Database,
// Only enabled for admins // Only enabled for admins
isEnabled: ({ auth, user, isCloud }) => !!(auth?.role === "admin"), isEnabled: ({ auth, user, isCloud }) => !!(auth?.role === "owner"),
}, },
{ {
@@ -317,7 +317,7 @@ const MENU: Menu = {
url: "/dashboard/settings/certificates", url: "/dashboard/settings/certificates",
icon: ShieldCheck, icon: ShieldCheck,
// Only enabled for admins // Only enabled for admins
isEnabled: ({ auth, user, isCloud }) => !!(auth?.role === "admin"), isEnabled: ({ auth, user, isCloud }) => !!(auth?.role === "owner"),
}, },
{ {
isSingle: true, isSingle: true,
@@ -326,7 +326,7 @@ const MENU: Menu = {
icon: Boxes, icon: Boxes,
// Only enabled for admins in non-cloud environments // Only enabled for admins in non-cloud environments
isEnabled: ({ auth, user, isCloud }) => isEnabled: ({ auth, user, isCloud }) =>
!!(auth?.role === "admin" && !isCloud), !!(auth?.role === "owner" && !isCloud),
}, },
{ {
isSingle: true, isSingle: true,
@@ -334,7 +334,7 @@ const MENU: Menu = {
url: "/dashboard/settings/notifications", url: "/dashboard/settings/notifications",
icon: Bell, icon: Bell,
// Only enabled for admins // Only enabled for admins
isEnabled: ({ auth, user, isCloud }) => !!(auth?.role === "admin"), isEnabled: ({ auth, user, isCloud }) => !!(auth?.role === "owner"),
}, },
{ {
isSingle: true, isSingle: true,
@@ -343,7 +343,7 @@ const MENU: Menu = {
icon: CreditCard, icon: CreditCard,
// Only enabled for admins in cloud environments // Only enabled for admins in cloud environments
isEnabled: ({ auth, user, isCloud }) => isEnabled: ({ auth, user, isCloud }) =>
!!(auth?.role === "admin" && isCloud), !!(auth?.role === "owner" && isCloud),
}, },
], ],
@@ -537,7 +537,7 @@ export default function Page({ children }: Props) {
authId: auth?.id || "", authId: auth?.id || "",
}, },
{ {
enabled: !!auth?.id && auth?.role === "user", enabled: !!auth?.id && auth?.role === "member",
}, },
); );
@@ -557,7 +557,7 @@ export default function Page({ children }: Props) {
// const showProjectsButton = // const showProjectsButton =
// currentPath === "/dashboard/projects" && // currentPath === "/dashboard/projects" &&
// (auth?.rol === "admin" || user?.canCreateProjects); // (auth?.rol === "owner" || user?.canCreateProjects);
return ( return (
<SidebarProvider <SidebarProvider
@@ -783,7 +783,7 @@ export default function Page({ children }: Props) {
</SidebarMenuButton> </SidebarMenuButton>
</SidebarMenuItem> </SidebarMenuItem>
))} ))}
{!isCloud && auth?.role === "admin" && ( {!isCloud && auth?.role === "owner" && (
<SidebarMenuItem> <SidebarMenuItem>
<SidebarMenuButton asChild> <SidebarMenuButton asChild>
<UpdateServerButton /> <UpdateServerButton />

View File

@@ -37,7 +37,7 @@ export const UserNav = () => {
authId: data?.id || "", authId: data?.id || "",
}, },
{ {
enabled: !!data?.id && data?.rol === "user", enabled: !!data?.id && data?.role === "member",
}, },
); );
const { locale, setLocale } = useLocale(); const { locale, setLocale } = useLocale();
@@ -96,7 +96,7 @@ export const UserNav = () => {
> >
Monitoring Monitoring
</DropdownMenuItem> </DropdownMenuItem>
{(data?.rol === "admin" || user?.canAccessToTraefikFiles) && ( {(data?.role === "owner" || user?.canAccessToTraefikFiles) && (
<DropdownMenuItem <DropdownMenuItem
className="cursor-pointer" className="cursor-pointer"
onClick={() => { onClick={() => {
@@ -106,7 +106,7 @@ export const UserNav = () => {
Traefik Traefik
</DropdownMenuItem> </DropdownMenuItem>
)} )}
{(data?.rol === "admin" || user?.canAccessToDocker) && ( {(data?.role === "owner" || user?.canAccessToDocker) && (
<DropdownMenuItem <DropdownMenuItem
className="cursor-pointer" className="cursor-pointer"
onClick={() => { onClick={() => {
@@ -119,7 +119,7 @@ export const UserNav = () => {
</DropdownMenuItem> </DropdownMenuItem>
)} )}
{data?.rol === "admin" && ( {data?.role === "owner" && (
<DropdownMenuItem <DropdownMenuItem
className="cursor-pointer" className="cursor-pointer"
onClick={() => { onClick={() => {
@@ -140,7 +140,7 @@ export const UserNav = () => {
> >
Profile Profile
</DropdownMenuItem> </DropdownMenuItem>
{data?.rol === "admin" && ( {data?.role === "owner" && (
<DropdownMenuItem <DropdownMenuItem
className="cursor-pointer" className="cursor-pointer"
onClick={() => { onClick={() => {
@@ -151,7 +151,7 @@ export const UserNav = () => {
</DropdownMenuItem> </DropdownMenuItem>
)} )}
{data?.rol === "admin" && ( {data?.role === "owner" && (
<DropdownMenuItem <DropdownMenuItem
className="cursor-pointer" className="cursor-pointer"
onClick={() => { onClick={() => {
@@ -164,7 +164,7 @@ export const UserNav = () => {
</> </>
)} )}
</DropdownMenuGroup> </DropdownMenuGroup>
{isCloud && data?.rol === "admin" && ( {isCloud && data?.role === "owner" && (
<DropdownMenuItem <DropdownMenuItem
className="cursor-pointer" className="cursor-pointer"
onClick={() => { onClick={() => {

View File

@@ -42,7 +42,7 @@ export default async function handler(
const auth = await findAuthById(value as string); const auth = await findAuthById(value as string);
let adminId = ""; let adminId = "";
if (auth.role === "admin") { if (auth.role === "owner") {
const admin = await findAdminByAuthId(auth.id); const admin = await findAdminByAuthId(auth.id);
adminId = admin.adminId; adminId = admin.adminId;
} else { } else {

View File

@@ -53,7 +53,7 @@ export async function getServerSideProps(
await helpers.project.all.prefetch(); await helpers.project.all.prefetch();
const auth = await helpers.auth.get.fetch(); const auth = await helpers.auth.get.fetch();
if (auth.role === "user") { if (auth.role === "member") {
const user = await helpers.user.byAuthId.fetch({ const user = await helpers.user.byAuthId.fetch({
authId: auth.id, authId: auth.id,
}); });

View File

@@ -206,7 +206,7 @@ const Project = (
authId: auth?.id || "", authId: auth?.id || "",
}, },
{ {
enabled: !!auth?.id && auth?.role === "user", enabled: !!auth?.id && auth?.role === "member",
}, },
); );
const { data, isLoading, refetch } = api.project.one.useQuery({ projectId }); const { data, isLoading, refetch } = api.project.one.useQuery({ projectId });
@@ -335,7 +335,7 @@ const Project = (
</CardTitle> </CardTitle>
<CardDescription>{data?.description}</CardDescription> <CardDescription>{data?.description}</CardDescription>
</CardHeader> </CardHeader>
{(auth?.role === "admin" || user?.canCreateServices) && ( {(auth?.role === "owner" || user?.canCreateServices) && (
<div className="flex flex-row gap-4 flex-wrap"> <div className="flex flex-row gap-4 flex-wrap">
<ProjectEnvironment projectId={projectId}> <ProjectEnvironment projectId={projectId}>
<Button variant="outline">Project Environment</Button> <Button variant="outline">Project Environment</Button>

View File

@@ -93,7 +93,7 @@ const Service = (
authId: auth?.id || "", authId: auth?.id || "",
}, },
{ {
enabled: !!auth?.id && auth?.role === "user", enabled: !!auth?.id && auth?.role === "member",
}, },
); );
@@ -186,7 +186,7 @@ const Service = (
<div className="flex flex-row gap-2 justify-end"> <div className="flex flex-row gap-2 justify-end">
<UpdateApplication applicationId={applicationId} /> <UpdateApplication applicationId={applicationId} />
{(auth?.role === "admin" || user?.canDeleteServices) && ( {(auth?.role === "owner" || user?.canDeleteServices) && (
<DeleteService id={applicationId} type="application" /> <DeleteService id={applicationId} type="application" />
)} )}
</div> </div>

View File

@@ -87,7 +87,7 @@ const Service = (
authId: auth?.id || "", authId: auth?.id || "",
}, },
{ {
enabled: !!auth?.id && auth?.role === "user", enabled: !!auth?.id && auth?.role === "member",
}, },
); );
@@ -181,7 +181,7 @@ const Service = (
<div className="flex flex-row gap-2 justify-end"> <div className="flex flex-row gap-2 justify-end">
<UpdateCompose composeId={composeId} /> <UpdateCompose composeId={composeId} />
{(auth?.role === "admin" || user?.canDeleteServices) && ( {(auth?.role === "owner" || user?.canDeleteServices) && (
<DeleteService id={composeId} type="compose" /> <DeleteService id={composeId} type="compose" />
)} )}
</div> </div>

View File

@@ -68,7 +68,7 @@ const Mariadb = (
authId: auth?.id || "", authId: auth?.id || "",
}, },
{ {
enabled: !!auth?.id && auth?.role === "user", enabled: !!auth?.id && auth?.role === "member",
}, },
); );
const { data: isCloud } = api.settings.isCloud.useQuery(); const { data: isCloud } = api.settings.isCloud.useQuery();
@@ -154,7 +154,7 @@ const Mariadb = (
</div> </div>
<div className="flex flex-row gap-2 justify-end"> <div className="flex flex-row gap-2 justify-end">
<UpdateMariadb mariadbId={mariadbId} /> <UpdateMariadb mariadbId={mariadbId} />
{(auth?.role === "admin" || user?.canDeleteServices) && ( {(auth?.role === "owner" || user?.canDeleteServices) && (
<DeleteService id={mariadbId} type="mariadb" /> <DeleteService id={mariadbId} type="mariadb" />
)} )}
</div> </div>

View File

@@ -68,7 +68,7 @@ const Mongo = (
authId: auth?.id || "", authId: auth?.id || "",
}, },
{ {
enabled: !!auth?.id && auth?.role === "user", enabled: !!auth?.id && auth?.role === "member",
}, },
); );
@@ -156,7 +156,7 @@ const Mongo = (
<div className="flex flex-row gap-2 justify-end"> <div className="flex flex-row gap-2 justify-end">
<UpdateMongo mongoId={mongoId} /> <UpdateMongo mongoId={mongoId} />
{(auth?.role === "admin" || user?.canDeleteServices) && ( {(auth?.role === "owner" || user?.canDeleteServices) && (
<DeleteService id={mongoId} type="mongo" /> <DeleteService id={mongoId} type="mongo" />
)} )}
</div> </div>

View File

@@ -67,7 +67,7 @@ const MySql = (
authId: auth?.id || "", authId: auth?.id || "",
}, },
{ {
enabled: !!auth?.id && auth?.role === "user", enabled: !!auth?.id && auth?.role === "member",
}, },
); );
@@ -156,7 +156,7 @@ const MySql = (
<div className="flex flex-row gap-2 justify-end"> <div className="flex flex-row gap-2 justify-end">
<UpdateMysql mysqlId={mysqlId} /> <UpdateMysql mysqlId={mysqlId} />
{(auth?.role === "admin" || user?.canDeleteServices) && ( {(auth?.role === "owner" || user?.canDeleteServices) && (
<DeleteService id={mysqlId} type="mysql" /> <DeleteService id={mysqlId} type="mysql" />
)} )}
</div> </div>

View File

@@ -66,7 +66,7 @@ const Postgresql = (
authId: auth?.id || "", authId: auth?.id || "",
}, },
{ {
enabled: !!auth?.id && auth?.role === "user", enabled: !!auth?.id && auth?.role === "member",
}, },
); );
const { data: monitoring } = api.admin.getMetricsToken.useQuery(); const { data: monitoring } = api.admin.getMetricsToken.useQuery();
@@ -154,7 +154,7 @@ const Postgresql = (
<div className="flex flex-row gap-2 justify-end"> <div className="flex flex-row gap-2 justify-end">
<UpdatePostgres postgresId={postgresId} /> <UpdatePostgres postgresId={postgresId} />
{(auth?.role === "admin" || user?.canDeleteServices) && ( {(auth?.role === "owner" || user?.canDeleteServices) && (
<DeleteService id={postgresId} type="postgres" /> <DeleteService id={postgresId} type="postgres" />
)} )}
</div> </div>

View File

@@ -67,7 +67,7 @@ const Redis = (
authId: auth?.id || "", authId: auth?.id || "",
}, },
{ {
enabled: !!auth?.id && auth?.role === "user", enabled: !!auth?.id && auth?.role === "member",
}, },
); );
@@ -155,7 +155,7 @@ const Redis = (
<div className="flex flex-row gap-2 justify-end"> <div className="flex flex-row gap-2 justify-end">
<UpdateRedis redisId={redisId} /> <UpdateRedis redisId={redisId} />
{(auth?.role === "admin" || user?.canDeleteServices) && ( {(auth?.role === "owner" || user?.canDeleteServices) && (
<DeleteService id={redisId} type="redis" /> <DeleteService id={redisId} type="redis" />
)} )}
</div> </div>

View File

@@ -30,7 +30,7 @@ export async function getServerSideProps(
} }
const { req, res } = ctx; const { req, res } = ctx;
const { user, session } = await validateRequest(req, res); const { user, session } = await validateRequest(req, res);
if (!user || user.role === "user") { if (!user || user.role === "member") {
return { return {
redirect: { redirect: {
permanent: true, permanent: true,

View File

@@ -25,7 +25,7 @@ export async function getServerSideProps(
) { ) {
const { req, res } = ctx; const { req, res } = ctx;
const { user, session } = await validateRequest(req, res); const { user, session } = await validateRequest(req, res);
if (!user || user.role === "user") { if (!user || user.role === "member") {
return { return {
redirect: { redirect: {
permanent: true, permanent: true,

View File

@@ -34,7 +34,7 @@ export async function getServerSideProps(
}; };
} }
const { user, session } = await validateRequest(ctx.req, ctx.res); const { user, session } = await validateRequest(ctx.req, ctx.res);
if (!user || user.role === "user") { if (!user || user.role === "member") {
return { return {
redirect: { redirect: {
permanent: true, permanent: true,

View File

@@ -26,7 +26,7 @@ export async function getServerSideProps(
) { ) {
const { req, res } = ctx; const { req, res } = ctx;
const { user, session } = await validateRequest(req, res); const { user, session } = await validateRequest(req, res);
if (!user || user.role === "user") { if (!user || user.role === "member") {
return { return {
redirect: { redirect: {
permanent: true, permanent: true,

View File

@@ -51,7 +51,7 @@ export async function getServerSideProps(
await helpers.settings.isCloud.prefetch(); await helpers.settings.isCloud.prefetch();
const auth = await helpers.auth.get.fetch(); const auth = await helpers.auth.get.fetch();
if (auth.role === "user") { if (auth.role === "member") {
const user = await helpers.user.byAuthId.fetch({ const user = await helpers.user.byAuthId.fetch({
authId: auth.id, authId: auth.id,
}); });

View File

@@ -190,7 +190,7 @@ export async function getServerSideProps(
}, },
}; };
} }
if (user.role === "user") { if (user.role === "member") {
return { return {
redirect: { redirect: {
permanent: true, permanent: true,

View File

@@ -26,7 +26,7 @@ export async function getServerSideProps(
) { ) {
const { req, res } = ctx; const { req, res } = ctx;
const { user, session } = await validateRequest(req, res); const { user, session } = await validateRequest(req, res);
if (!user || user.role === "user") { if (!user || user.role === "member") {
return { return {
redirect: { redirect: {
permanent: true, permanent: true,

View File

@@ -19,7 +19,7 @@ const Page = () => {
authId: data?.id || "", authId: data?.id || "",
}, },
{ {
enabled: !!data?.id && data?.role === "user", enabled: !!data?.id && data?.role === "member",
}, },
); );
@@ -28,7 +28,7 @@ const Page = () => {
<div className="w-full"> <div className="w-full">
<div className="h-full rounded-xl max-w-5xl mx-auto flex flex-col gap-4"> <div className="h-full rounded-xl max-w-5xl mx-auto flex flex-col gap-4">
<ProfileForm /> <ProfileForm />
{(user?.canAccessToAPI || data?.role === "admin") && <GenerateToken />} {(user?.canAccessToAPI || data?.role === "owner") && <GenerateToken />}
{isCloud && <RemoveSelfAccount />} {isCloud && <RemoveSelfAccount />}
</div> </div>
@@ -62,7 +62,7 @@ export async function getServerSideProps(
await helpers.settings.isCloud.prefetch(); await helpers.settings.isCloud.prefetch();
await helpers.auth.get.prefetch(); await helpers.auth.get.prefetch();
if (user?.role === "user") { if (user?.role === "member") {
await helpers.user.byAuthId.prefetch({ await helpers.user.byAuthId.prefetch({
authId: user.authId, authId: user.authId,
}); });

View File

@@ -26,7 +26,7 @@ export async function getServerSideProps(
) { ) {
const { req, res } = ctx; const { req, res } = ctx;
const { user, session } = await validateRequest(req, res); const { user, session } = await validateRequest(req, res);
if (!user || user.role === "user") { if (!user || user.role === "member") {
return { return {
redirect: { redirect: {
permanent: true, permanent: true,

View File

@@ -107,7 +107,7 @@ export async function getServerSideProps(
}, },
}; };
} }
if (user.role === "user") { if (user.role === "member") {
return { return {
redirect: { redirect: {
permanent: true, permanent: true,

View File

@@ -36,7 +36,7 @@ export async function getServerSideProps(
}, },
}; };
} }
if (user.role === "user") { if (user.role === "member") {
return { return {
redirect: { redirect: {
permanent: true, permanent: true,

View File

@@ -51,7 +51,7 @@ export async function getServerSideProps(
const auth = await helpers.auth.get.fetch(); const auth = await helpers.auth.get.fetch();
await helpers.settings.isCloud.prefetch(); await helpers.settings.isCloud.prefetch();
if (auth.role === "user") { if (auth.role === "member") {
const user = await helpers.user.byAuthId.fetch({ const user = await helpers.user.byAuthId.fetch({
authId: auth.id, authId: auth.id,
}); });

View File

@@ -26,7 +26,7 @@ export async function getServerSideProps(
) { ) {
const { req, res } = ctx; const { req, res } = ctx;
const { user, session } = await validateRequest(req, res); const { user, session } = await validateRequest(req, res);
if (!user || user.role === "user") { if (!user || user.role === "member") {
return { return {
redirect: { redirect: {
permanent: true, permanent: true,

View File

@@ -53,7 +53,7 @@ export async function getServerSideProps(
await helpers.project.all.prefetch(); await helpers.project.all.prefetch();
const auth = await helpers.auth.get.fetch(); const auth = await helpers.auth.get.fetch();
if (auth.role === "user") { if (auth.role === "member") {
const user = await helpers.user.byAuthId.fetch({ const user = await helpers.user.byAuthId.fetch({
authId: auth.id, authId: auth.id,
}); });

View File

@@ -53,7 +53,7 @@ export async function getServerSideProps(
await helpers.project.all.prefetch(); await helpers.project.all.prefetch();
const auth = await helpers.auth.get.fetch(); const auth = await helpers.auth.get.fetch();
if (auth.role === "user") { if (auth.role === "member") {
const user = await helpers.user.byAuthId.fetch({ const user = await helpers.user.byAuthId.fetch({
authId: auth.id, authId: auth.id,
}); });

View File

@@ -58,7 +58,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
}, },
transformer: superjson, transformer: superjson,
}); });
if (user.role === "user") { if (user.role === "member") {
const result = await helpers.user.byAuthId.fetch({ const result = await helpers.user.byAuthId.fetch({
authId: user.id, authId: user.id,
}); });

View File

@@ -39,7 +39,7 @@ export const adminRouter = createTRPCRouter({
update: adminProcedure update: adminProcedure
.input(apiUpdateAdmin) .input(apiUpdateAdmin)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
message: "You are not allowed to update this admin", message: "You are not allowed to update this admin",

View File

@@ -60,7 +60,7 @@ export const applicationRouter = createTRPCRouter({
.input(apiCreateApplication) .input(apiCreateApplication)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
try { try {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.projectId, "create"); await checkServiceAccess(ctx.user.id, input.projectId, "create");
} }
@@ -80,7 +80,7 @@ export const applicationRouter = createTRPCRouter({
} }
const newApplication = await createApplication(input); const newApplication = await createApplication(input);
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await addNewService(ctx.user.id, newApplication.applicationId); await addNewService(ctx.user.id, newApplication.applicationId);
} }
return newApplication; return newApplication;
@@ -98,7 +98,7 @@ export const applicationRouter = createTRPCRouter({
one: protectedProcedure one: protectedProcedure
.input(apiFindOneApplication) .input(apiFindOneApplication)
.query(async ({ input, ctx }) => { .query(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.applicationId, "access"); await checkServiceAccess(ctx.user.id, input.applicationId, "access");
} }
const application = await findApplicationById(input.applicationId); const application = await findApplicationById(input.applicationId);
@@ -140,7 +140,7 @@ export const applicationRouter = createTRPCRouter({
delete: protectedProcedure delete: protectedProcedure
.input(apiFindOneApplication) .input(apiFindOneApplication)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.applicationId, "delete"); await checkServiceAccess(ctx.user.id, input.applicationId, "delete");
} }
const application = await findApplicationById(input.applicationId); const application = await findApplicationById(input.applicationId);

View File

@@ -176,6 +176,9 @@ export const authRouter = createTRPCRouter({
eq(member.userId, ctx.user.id), eq(member.userId, ctx.user.id),
eq(member.organizationId, ctx.session?.activeOrganizationId || ""), eq(member.organizationId, ctx.session?.activeOrganizationId || ""),
), ),
with: {
user: true,
},
}); });
return memberResult; return memberResult;
@@ -251,7 +254,7 @@ export const authRouter = createTRPCRouter({
await lucia.invalidateSession(session.id); await lucia.invalidateSession(session.id);
res.setHeader("Set-Cookie", lucia.createBlankSessionCookie().serialize()); res.setHeader("Set-Cookie", lucia.createBlankSessionCookie().serialize());
if (ctx.user.rol === "admin") { if (ctx.user.rol === "owner") {
await removeAdminByAuthId(ctx.user.authId); await removeAdminByAuthId(ctx.user.authId);
} else { } else {
await removeUserByAuthId(ctx.user.authId); await removeUserByAuthId(ctx.user.authId);

View File

@@ -61,7 +61,7 @@ export const composeRouter = createTRPCRouter({
.input(apiCreateCompose) .input(apiCreateCompose)
.mutation(async ({ ctx, input }) => { .mutation(async ({ ctx, input }) => {
try { try {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.projectId, "create"); await checkServiceAccess(ctx.user.id, input.projectId, "create");
} }
@@ -80,7 +80,7 @@ export const composeRouter = createTRPCRouter({
} }
const newService = await createCompose(input); const newService = await createCompose(input);
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await addNewService(ctx.user.id, newService.composeId); await addNewService(ctx.user.id, newService.composeId);
} }
@@ -93,7 +93,7 @@ export const composeRouter = createTRPCRouter({
one: protectedProcedure one: protectedProcedure
.input(apiFindCompose) .input(apiFindCompose)
.query(async ({ input, ctx }) => { .query(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.composeId, "access"); await checkServiceAccess(ctx.user.id, input.composeId, "access");
} }
@@ -122,7 +122,7 @@ export const composeRouter = createTRPCRouter({
delete: protectedProcedure delete: protectedProcedure
.input(apiDeleteCompose) .input(apiDeleteCompose)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.composeId, "delete"); await checkServiceAccess(ctx.user.id, input.composeId, "delete");
} }
const composeResult = await findComposeById(input.composeId); const composeResult = await findComposeById(input.composeId);
@@ -376,7 +376,7 @@ export const composeRouter = createTRPCRouter({
deployTemplate: protectedProcedure deployTemplate: protectedProcedure
.input(apiCreateComposeByTemplate) .input(apiCreateComposeByTemplate)
.mutation(async ({ ctx, input }) => { .mutation(async ({ ctx, input }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.projectId, "create"); await checkServiceAccess(ctx.user.id, input.projectId, "create");
} }
@@ -419,7 +419,7 @@ export const composeRouter = createTRPCRouter({
isolatedDeployment: true, isolatedDeployment: true,
}); });
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await addNewService(ctx.user.id, compose.composeId); await addNewService(ctx.user.id, compose.composeId);
} }

View File

@@ -37,7 +37,7 @@ export const mariadbRouter = createTRPCRouter({
.input(apiCreateMariaDB) .input(apiCreateMariaDB)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
try { try {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.projectId, "create"); await checkServiceAccess(ctx.user.id, input.projectId, "create");
} }
@@ -56,7 +56,7 @@ export const mariadbRouter = createTRPCRouter({
}); });
} }
const newMariadb = await createMariadb(input); const newMariadb = await createMariadb(input);
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await addNewService(ctx.user.id, newMariadb.mariadbId); await addNewService(ctx.user.id, newMariadb.mariadbId);
} }
@@ -79,7 +79,7 @@ export const mariadbRouter = createTRPCRouter({
one: protectedProcedure one: protectedProcedure
.input(apiFindOneMariaDB) .input(apiFindOneMariaDB)
.query(async ({ input, ctx }) => { .query(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.mariadbId, "access"); await checkServiceAccess(ctx.user.id, input.mariadbId, "access");
} }
const mariadb = await findMariadbById(input.mariadbId); const mariadb = await findMariadbById(input.mariadbId);
@@ -201,7 +201,7 @@ export const mariadbRouter = createTRPCRouter({
remove: protectedProcedure remove: protectedProcedure
.input(apiFindOneMariaDB) .input(apiFindOneMariaDB)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.mariadbId, "delete"); await checkServiceAccess(ctx.user.id, input.mariadbId, "delete");
} }

View File

@@ -36,7 +36,7 @@ export const mongoRouter = createTRPCRouter({
.input(apiCreateMongo) .input(apiCreateMongo)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
try { try {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.projectId, "create"); await checkServiceAccess(ctx.user.id, input.projectId, "create");
} }
@@ -55,7 +55,7 @@ export const mongoRouter = createTRPCRouter({
}); });
} }
const newMongo = await createMongo(input); const newMongo = await createMongo(input);
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await addNewService(ctx.user.id, newMongo.mongoId); await addNewService(ctx.user.id, newMongo.mongoId);
} }
@@ -82,7 +82,7 @@ export const mongoRouter = createTRPCRouter({
one: protectedProcedure one: protectedProcedure
.input(apiFindOneMongo) .input(apiFindOneMongo)
.query(async ({ input, ctx }) => { .query(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.mongoId, "access"); await checkServiceAccess(ctx.user.id, input.mongoId, "access");
} }
@@ -242,7 +242,7 @@ export const mongoRouter = createTRPCRouter({
remove: protectedProcedure remove: protectedProcedure
.input(apiFindOneMongo) .input(apiFindOneMongo)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.mongoId, "delete"); await checkServiceAccess(ctx.user.id, input.mongoId, "delete");
} }

View File

@@ -38,7 +38,7 @@ export const mysqlRouter = createTRPCRouter({
.input(apiCreateMySql) .input(apiCreateMySql)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
try { try {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.projectId, "create"); await checkServiceAccess(ctx.user.id, input.projectId, "create");
} }
@@ -58,7 +58,7 @@ export const mysqlRouter = createTRPCRouter({
} }
const newMysql = await createMysql(input); const newMysql = await createMysql(input);
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await addNewService(ctx.user.id, newMysql.mysqlId); await addNewService(ctx.user.id, newMysql.mysqlId);
} }
@@ -85,7 +85,7 @@ export const mysqlRouter = createTRPCRouter({
one: protectedProcedure one: protectedProcedure
.input(apiFindOneMySql) .input(apiFindOneMySql)
.query(async ({ input, ctx }) => { .query(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.mysqlId, "access"); await checkServiceAccess(ctx.user.id, input.mysqlId, "access");
} }
const mysql = await findMySqlById(input.mysqlId); const mysql = await findMySqlById(input.mysqlId);
@@ -240,7 +240,7 @@ export const mysqlRouter = createTRPCRouter({
remove: protectedProcedure remove: protectedProcedure
.input(apiFindOneMySql) .input(apiFindOneMySql)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.mysqlId, "delete"); await checkServiceAccess(ctx.user.id, input.mysqlId, "delete");
} }
const mongo = await findMySqlById(input.mysqlId); const mongo = await findMySqlById(input.mysqlId);

View File

@@ -44,7 +44,7 @@ export const postgresRouter = createTRPCRouter({
.input(apiCreatePostgres) .input(apiCreatePostgres)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
try { try {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.projectId, "create"); await checkServiceAccess(ctx.user.id, input.projectId, "create");
} }
@@ -63,7 +63,7 @@ export const postgresRouter = createTRPCRouter({
}); });
} }
const newPostgres = await createPostgres(input); const newPostgres = await createPostgres(input);
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await addNewService(ctx.user.id, newPostgres.postgresId); await addNewService(ctx.user.id, newPostgres.postgresId);
} }
@@ -90,7 +90,7 @@ export const postgresRouter = createTRPCRouter({
one: protectedProcedure one: protectedProcedure
.input(apiFindOnePostgres) .input(apiFindOnePostgres)
.query(async ({ input, ctx }) => { .query(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.postgresId, "access"); await checkServiceAccess(ctx.user.id, input.postgresId, "access");
} }
@@ -221,7 +221,7 @@ export const postgresRouter = createTRPCRouter({
remove: protectedProcedure remove: protectedProcedure
.input(apiFindOnePostgres) .input(apiFindOnePostgres)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.postgresId, "delete"); await checkServiceAccess(ctx.user.id, input.postgresId, "delete");
} }
const postgres = await findPostgresById(input.postgresId); const postgres = await findPostgresById(input.postgresId);

View File

@@ -36,7 +36,7 @@ export const projectRouter = createTRPCRouter({
.input(apiCreateProject) .input(apiCreateProject)
.mutation(async ({ ctx, input }) => { .mutation(async ({ ctx, input }) => {
try { try {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkProjectAccess(ctx.user.id, "create"); await checkProjectAccess(ctx.user.id, "create");
} }
@@ -50,7 +50,7 @@ export const projectRouter = createTRPCRouter({
} }
const project = await createProject(input, ctx.user.ownerId); const project = await createProject(input, ctx.user.ownerId);
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await addNewProject(ctx.user.id, project.projectId); await addNewProject(ctx.user.id, project.projectId);
} }
@@ -67,7 +67,7 @@ export const projectRouter = createTRPCRouter({
one: protectedProcedure one: protectedProcedure
.input(apiFindOneProject) .input(apiFindOneProject)
.query(async ({ input, ctx }) => { .query(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
const { accessedServices } = await findUserByAuthId(ctx.user.id); const { accessedServices } = await findUserByAuthId(ctx.user.id);
await checkProjectAccess(ctx.user.id, "access", input.projectId); await checkProjectAccess(ctx.user.id, "access", input.projectId);
@@ -125,7 +125,7 @@ export const projectRouter = createTRPCRouter({
}), }),
all: protectedProcedure.query(async ({ ctx }) => { all: protectedProcedure.query(async ({ ctx }) => {
// console.log(ctx.user); // console.log(ctx.user);
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
const { accessedProjects, accessedServices } = await findUserById( const { accessedProjects, accessedServices } = await findUserById(
ctx.user.id, ctx.user.id,
); );
@@ -203,7 +203,7 @@ export const projectRouter = createTRPCRouter({
.input(apiRemoveProject) .input(apiRemoveProject)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
try { try {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkProjectAccess(ctx.user.id, "delete"); await checkProjectAccess(ctx.user.id, "delete");
} }
const currentProject = await findProjectById(input.projectId); const currentProject = await findProjectById(input.projectId);

View File

@@ -36,7 +36,7 @@ export const redisRouter = createTRPCRouter({
.input(apiCreateRedis) .input(apiCreateRedis)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
try { try {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.projectId, "create"); await checkServiceAccess(ctx.user.id, input.projectId, "create");
} }
@@ -55,7 +55,7 @@ export const redisRouter = createTRPCRouter({
}); });
} }
const newRedis = await createRedis(input); const newRedis = await createRedis(input);
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await addNewService(ctx.user.id, newRedis.redisId); await addNewService(ctx.user.id, newRedis.redisId);
} }
@@ -75,7 +75,7 @@ export const redisRouter = createTRPCRouter({
one: protectedProcedure one: protectedProcedure
.input(apiFindOneRedis) .input(apiFindOneRedis)
.query(async ({ input, ctx }) => { .query(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.redisId, "access"); await checkServiceAccess(ctx.user.id, input.redisId, "access");
} }
@@ -232,7 +232,7 @@ export const redisRouter = createTRPCRouter({
remove: protectedProcedure remove: protectedProcedure
.input(apiFindOneRedis) .input(apiFindOneRedis)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
await checkServiceAccess(ctx.user.id, input.redisId, "delete"); await checkServiceAccess(ctx.user.id, input.redisId, "delete");
} }

View File

@@ -382,7 +382,7 @@ export const settingsRouter = createTRPCRouter({
.input(apiServerSchema) .input(apiServerSchema)
.query(async ({ ctx, input }) => { .query(async ({ ctx, input }) => {
try { try {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
const canAccess = await canAccessToTraefikFiles(ctx.user.authId); const canAccess = await canAccessToTraefikFiles(ctx.user.authId);
if (!canAccess) { if (!canAccess) {
@@ -400,7 +400,7 @@ export const settingsRouter = createTRPCRouter({
updateTraefikFile: protectedProcedure updateTraefikFile: protectedProcedure
.input(apiModifyTraefikConfig) .input(apiModifyTraefikConfig)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
const canAccess = await canAccessToTraefikFiles(ctx.user.authId); const canAccess = await canAccessToTraefikFiles(ctx.user.authId);
if (!canAccess) { if (!canAccess) {
@@ -418,7 +418,7 @@ export const settingsRouter = createTRPCRouter({
readTraefikFile: protectedProcedure readTraefikFile: protectedProcedure
.input(apiReadTraefikConfig) .input(apiReadTraefikConfig)
.query(async ({ input, ctx }) => { .query(async ({ input, ctx }) => {
if (ctx.user.rol === "user") { if (ctx.user.rol === "member") {
const canAccess = await canAccessToTraefikFiles(ctx.user.authId); const canAccess = await canAccessToTraefikFiles(ctx.user.authId);
if (!canAccess) { if (!canAccess) {

View File

@@ -32,7 +32,7 @@ import { ZodError } from "zod";
interface CreateContextOptions { interface CreateContextOptions {
user: (User & { rol: "admin" | "user"; ownerId: string }) | null; user: (User & { rol: "admin" | "user"; ownerId: string }) | null;
session: (Session & { activeOrganizationId: string }) | null; session: (Session & { activeOrganizationId?: string }) | null;
req: CreateNextContextOptions["req"]; req: CreateNextContextOptions["req"];
res: CreateNextContextOptions["res"]; res: CreateNextContextOptions["res"];
} }
@@ -67,31 +67,35 @@ export const createTRPCContext = async (opts: CreateNextContextOptions) => {
const { req, res } = opts; const { req, res } = opts;
// Get from the request // Get from the request
let { session, user } = await validateRequest(req); const { session, user } = await validateRequest(req);
if (!session) { // if (!session) {
const cookieResult = await validateRequest(req); // const cookieResult = await validateRequest(req);
session = cookieResult.session; // session = cookieResult.session;
user = cookieResult.user; // user = cookieResult.user;
} // }
console.log("session", { session, user }); console.log("session", session);
console.log("user", user);
return createInnerTRPCContext({ return createInnerTRPCContext({
req, req,
res, res,
session: session, session: session
...((user && { ? {
user: { ...session,
...user, activeOrganizationId: session.activeOrganizationId ?? undefined,
email: user.email, }
rol: user.role, : null,
id: user.id, user: user
ownerId: user.ownerId, ? {
}, ...user,
}) || { email: user.email,
user: null, rol: user.role as "admin" | "user",
}), id: user.id,
ownerId: user.ownerId,
}
: null,
}); });
}; };

View File

@@ -71,10 +71,10 @@ export async function validateRequest(
} }
if (result.user) { if (result.user) {
try { try {
if (result.user?.rol === "admin") { if (result.user?.rol === "owner") {
const admin = await findAdminByAuthId(result.user.id); const admin = await findAdminByAuthId(result.user.id);
result.user.adminId = admin.adminId; result.user.adminId = admin.adminId;
} else if (result.user?.rol === "user") { } else if (result.user?.rol === "member") {
const userResult = await findUserByAuthId(result.user.id); const userResult = await findUserByAuthId(result.user.id);
result.user.adminId = userResult.adminId; result.user.adminId = userResult.adminId;
} }

View File

@@ -35,10 +35,10 @@ export const validateBearerToken = async (
const result = await luciaToken.validateSession(sessionId); const result = await luciaToken.validateSession(sessionId);
if (result.user) { if (result.user) {
if (result.user?.rol === "admin") { if (result.user?.rol === "owner") {
const admin = await findAdminByAuthId(result.user.id); const admin = await findAdminByAuthId(result.user.id);
result.user.adminId = admin.adminId; result.user.adminId = admin.adminId;
} else if (result.user?.rol === "user") { } else if (result.user?.rol === "member") {
const userResult = await findUserByAuthId(result.user.id); const userResult = await findUserByAuthId(result.user.id);
result.user.adminId = userResult.adminId; result.user.adminId = userResult.adminId;
} }
@@ -73,10 +73,10 @@ export const validateBearerTokenAPI = async (
const result = await luciaToken.validateSession(sessionId); const result = await luciaToken.validateSession(sessionId);
if (result.user) { if (result.user) {
if (result.user?.rol === "admin") { if (result.user?.rol === "owner") {
const admin = await findAdminByAuthId(result.user.id); const admin = await findAdminByAuthId(result.user.id);
result.user.adminId = admin.adminId; result.user.adminId = admin.adminId;
} else if (result.user?.rol === "user") { } else if (result.user?.rol === "member") {
const userResult = await findUserByAuthId(result.user.id); const userResult = await findUserByAuthId(result.user.id);
result.user.adminId = userResult.adminId; result.user.adminId = userResult.adminId;
} }

View File

@@ -75,9 +75,11 @@ export const auth = betterAuth({
additionalFields: { additionalFields: {
role: { role: {
type: "string", type: "string",
required: true,
}, },
ownerId: { ownerId: {
type: "string", type: "string",
required: true,
}, },
}, },
}, },

View File

@@ -268,7 +268,7 @@ export const getGitlabRepositories = async (gitlabId?: string) => {
if (groupName) { if (groupName) {
return full_path.toLowerCase().includes(groupName) && kind === "group"; return full_path.toLowerCase().includes(groupName) && kind === "group";
} }
return kind === "user"; return kind === "member";
}); });
const mappedRepositories = filteredRepos.map((repo: any) => { const mappedRepositories = filteredRepos.map((repo: any) => {
return { return {
@@ -442,7 +442,7 @@ export const testGitlabConnection = async (
if (groupName) { if (groupName) {
return full_path.toLowerCase().includes(groupName) && kind === "group"; return full_path.toLowerCase().includes(groupName) && kind === "group";
} }
return kind === "user"; return kind === "member";
}); });
return filteredRepos.length; return filteredRepos.length;