mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
fix: refactoring
This commit is contained in:
@@ -3,6 +3,10 @@ import { loggingMiddleware } from "@/middleware/loggingMiddleware";
|
|||||||
import { errorHandler } from "@/middleware/errorHandler";
|
import { errorHandler } from "@/middleware/errorHandler";
|
||||||
import { auth } from "@/lib/auth/auth";
|
import { auth } from "@/lib/auth/auth";
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
|
import { env } from "@/env.mjs";
|
||||||
|
import {User} from "@/db/schema/02_user";
|
||||||
|
|
||||||
|
const OPENAPI_ENABLED = String(env.OPENAPI_ENABLED).toLowerCase() === "true";
|
||||||
|
|
||||||
export async function proxy(request: NextRequest) {
|
export async function proxy(request: NextRequest) {
|
||||||
const url = request.nextUrl.clone();
|
const url = request.nextUrl.clone();
|
||||||
@@ -17,11 +21,13 @@ export async function proxy(request: NextRequest) {
|
|||||||
new URL(`/login?redirect=${redirectUrl}`, request.url),
|
new URL(`/login?redirect=${redirectUrl}`, request.url),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (session.user.banned) {
|
const user = session.user as User
|
||||||
|
|
||||||
|
if (user.banned) {
|
||||||
await auth.api.signOut({ headers: await headers() });
|
await auth.api.signOut({ headers: await headers() });
|
||||||
return NextResponse.redirect(new URL("/login?error=banned", request.url));
|
return NextResponse.redirect(new URL("/login?error=banned", request.url));
|
||||||
}
|
}
|
||||||
if (session.user.role === "pending") {
|
if (user.role === "pending") {
|
||||||
await auth.api.signOut({ headers: await headers() });
|
await auth.api.signOut({ headers: await headers() });
|
||||||
return NextResponse.redirect(
|
return NextResponse.redirect(
|
||||||
new URL(`/login?error=pending?redirect=${redirectUrl}`, request.url),
|
new URL(`/login?error=pending?redirect=${redirectUrl}`, request.url),
|
||||||
@@ -74,8 +80,16 @@ function checkRouteExists(pathname: string) {
|
|||||||
/^\/api\/health\/?$/,
|
/^\/api\/health\/?$/,
|
||||||
/^\/api\/google\/drive\/callback\/?$/,
|
/^\/api\/google\/drive\/callback\/?$/,
|
||||||
// v1 external API
|
// v1 external API
|
||||||
/^\/api\/v1\/docs\/?$/,
|
|
||||||
/^\/api\/v1\/openapi\/?$/,
|
|
||||||
|
...(OPENAPI_ENABLED
|
||||||
|
? [
|
||||||
|
/^\/api\/v1\/docs\/?$/,
|
||||||
|
/^\/api\/v1\/openapi\/?$/,
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
|
||||||
|
|
||||||
/^\/api\/v1\/agents\/?$/,
|
/^\/api\/v1\/agents\/?$/,
|
||||||
/^\/api\/v1\/agents\/[^/]+\/?$/,
|
/^\/api\/v1\/agents\/[^/]+\/?$/,
|
||||||
/^\/api\/v1\/agents\/[^/]+\/key\/?$/,
|
/^\/api\/v1\/agents\/[^/]+\/key\/?$/,
|
||||||
|
|||||||
@@ -98,6 +98,11 @@ export const env = createEnv({
|
|||||||
AUTH_ALLOW_UNLINKING: z.enum(["true", "false"]).default("true"),
|
AUTH_ALLOW_UNLINKING: z.enum(["true", "false"]).default("true"),
|
||||||
|
|
||||||
PRIVATE_PATH: z.string().optional(),
|
PRIVATE_PATH: z.string().optional(),
|
||||||
|
|
||||||
|
OPENAPI_ENABLED: z
|
||||||
|
.enum(["true", "false"])
|
||||||
|
.transform((val) => val === "true")
|
||||||
|
.default("false"),
|
||||||
},
|
},
|
||||||
client: {
|
client: {
|
||||||
NEXT_PUBLIC_PROJECT_VERSION: z.string().optional(),
|
NEXT_PUBLIC_PROJECT_VERSION: z.string().optional(),
|
||||||
@@ -170,5 +175,7 @@ export const env = createEnv({
|
|||||||
AUTH_DEFAULT_USER_NAME: process.env.AUTH_DEFAULT_USER_NAME,
|
AUTH_DEFAULT_USER_NAME: process.env.AUTH_DEFAULT_USER_NAME,
|
||||||
AUTH_DEFAULT_USER: process.env.AUTH_DEFAULT_USER,
|
AUTH_DEFAULT_USER: process.env.AUTH_DEFAULT_USER,
|
||||||
AUTH_DEFAULT_PASSWORD: process.env.AUTH_DEFAULT_PASSWORD,
|
AUTH_DEFAULT_PASSWORD: process.env.AUTH_DEFAULT_PASSWORD,
|
||||||
|
|
||||||
|
OPENAPI_ENABLED: process.env.OPENAPI_ENABLED,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { ReactNode } from "react";
|
import { ReactNode } from "react";
|
||||||
import {notFound} from "next/navigation";
|
import {notFound} from "next/navigation";
|
||||||
|
|
||||||
import {SidebarTrigger} from "@/components/ui/sidebar";
|
import {SidebarTrigger} from "@/components/ui/sidebar";
|
||||||
import {currentUser} from "@/lib/auth/current-user";
|
import {currentUser} from "@/lib/auth/current-user";
|
||||||
import {BreadCrumbsWrapper} from "@/components/common/bread-crumbs";
|
import {BreadCrumbsWrapper} from "@/components/common/bread-crumbs";
|
||||||
@@ -18,7 +17,6 @@ export const Header = async ({ actions }: { actions?: ReactNode } = {}) => {
|
|||||||
<SidebarTrigger className="-ml-1"/>
|
<SidebarTrigger className="-ml-1"/>
|
||||||
<BreadCrumbsWrapper/>
|
<BreadCrumbsWrapper/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<GitHubStarsButtonCustom/>
|
<GitHubStarsButtonCustom/>
|
||||||
{actions}
|
{actions}
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ import { ChevronsUpDown } from "lucide-react";
|
|||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
import { SidebarMenuButton } from "@/components/ui/sidebar";
|
import { SidebarMenuButton } from "@/components/ui/sidebar";
|
||||||
import { LoggedInDropdown } from "./logged-in-dropdown";
|
import { LoggedInDropdown } from "./logged-in-dropdown";
|
||||||
import { Account, Session, User } from "better-auth";
|
import { Account, Session } from "better-auth";
|
||||||
import { AuthProviderConfig } from "@/lib/auth/config";
|
import { AuthProviderConfig } from "@/lib/auth/config";
|
||||||
|
import {User} from "@/db/schema/02_user";
|
||||||
|
|
||||||
type LoggedInButtonClientProps = {
|
type LoggedInButtonClientProps = {
|
||||||
user: User;
|
user: User;
|
||||||
@@ -18,7 +19,6 @@ type LoggedInButtonClientProps = {
|
|||||||
export const LoggedInButtonClient = ({ user, sessions, currentSession, accounts, providers }: LoggedInButtonClientProps) => {
|
export const LoggedInButtonClient = ({ user, sessions, currentSession, accounts, providers }: LoggedInButtonClientProps) => {
|
||||||
return (
|
return (
|
||||||
<LoggedInDropdown
|
<LoggedInDropdown
|
||||||
// @ts-ignore
|
|
||||||
user={user}
|
user={user}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
sessions={sessions}
|
sessions={sessions}
|
||||||
|
|||||||
@@ -1,19 +1,12 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { PropsWithChildren, ReactNode, useState } from "react";
|
import { PropsWithChildren, ReactNode, useState } from "react";
|
||||||
|
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
import { LogOut, User } from "lucide-react";
|
import { LogOut, User } from "lucide-react";
|
||||||
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
|
||||||
|
|
||||||
import { signOut } from "@/lib/auth/auth-client";
|
import { signOut } from "@/lib/auth/auth-client";
|
||||||
|
|
||||||
import { ProfileModal } from "@/features/layout/profile-modal";
|
import { ProfileModal } from "@/features/layout/profile-modal";
|
||||||
|
|
||||||
import { Account, Session, User as UserType } from "@/db/schema/02_user";
|
import { Account, Session, User as UserType } from "@/db/schema/02_user";
|
||||||
|
|
||||||
import { AuthProviderConfig } from "@/lib/auth/config";
|
import { AuthProviderConfig } from "@/lib/auth/config";
|
||||||
|
|
||||||
export type LoggedInDropdownProps = PropsWithChildren<{
|
export type LoggedInDropdownProps = PropsWithChildren<{
|
||||||
|
|||||||
@@ -8,18 +8,17 @@ import {
|
|||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {OrganizationForm} from "@/features/organizations/organization-form";
|
import {OrganizationForm} from "@/features/organizations/organization-form";
|
||||||
import {ReactNode, useState} from "react";
|
import {useState} from "react";
|
||||||
import {Button, buttonVariants} from "@/components/ui/button";
|
import {buttonVariants} from "@/components/ui/button";
|
||||||
import {GearIcon} from "@radix-ui/react-icons";
|
import {GearIcon} from "@radix-ui/react-icons";
|
||||||
import {OrganizationWithMembers} from "@/db/schema/03_organization";
|
import {OrganizationWithMembers} from "@/db/schema/03_organization";
|
||||||
import {User} from "@/db/schema/02_user";
|
import {User} from "@/db/schema/02_user";
|
||||||
import {User as BetterAuthUser} from "better-auth";
|
|
||||||
import {useRouter} from "next/navigation";
|
import {useRouter} from "next/navigation";
|
||||||
|
|
||||||
type EditOrganizationDialogProps = {
|
type EditOrganizationDialogProps = {
|
||||||
organization: OrganizationWithMembers;
|
organization: OrganizationWithMembers;
|
||||||
users: User[];
|
users: User[];
|
||||||
currentUser: BetterAuthUser;
|
currentUser: User;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EditOrganizationDialog = ({
|
export const EditOrganizationDialog = ({
|
||||||
|
|||||||
@@ -24,14 +24,13 @@ import {
|
|||||||
updateOrganizationAction
|
updateOrganizationAction
|
||||||
} from "@/features/organizations/organization.action";
|
} from "@/features/organizations/organization.action";
|
||||||
import {toast} from "sonner";
|
import {toast} from "sonner";
|
||||||
import {User as BetterAuthUser} from "better-auth";
|
|
||||||
import {User} from "@/db/schema/02_user";
|
import {User} from "@/db/schema/02_user";
|
||||||
import {authClient} from "@/lib/auth/auth-client";
|
import {authClient} from "@/lib/auth/auth-client";
|
||||||
|
|
||||||
export type organizationFormProps = {
|
export type organizationFormProps = {
|
||||||
defaultValues?: OrganizationWithMembers;
|
defaultValues?: OrganizationWithMembers;
|
||||||
users: User[];
|
users: User[];
|
||||||
currentUser: BetterAuthUser;
|
currentUser: User;
|
||||||
onSuccess?: (data: any) => void;
|
onSuccess?: (data: any) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use server";
|
"use server";
|
||||||
import { auth } from "@/lib/auth/auth";
|
import { auth } from "@/lib/auth/auth";
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
|
import {User} from "@/db/schema/02_user";
|
||||||
|
|
||||||
export const currentUser = async () => {
|
export const currentUser = async () => {
|
||||||
const session = await auth.api.getSession({
|
const session = await auth.api.getSession({
|
||||||
@@ -11,5 +12,5 @@ export const currentUser = async () => {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return session.user;
|
return session.user as User;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user