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