Refactoring

This commit is contained in:
charles-gauthereau
2024-11-11 10:26:40 +01:00
parent cfd8803b16
commit fd77c601b5
7 changed files with 8854 additions and 13 deletions
+20
View File
@@ -0,0 +1,20 @@
// next-auth.d.ts
import NextAuth from "next-auth";
declare module "next-auth" {
interface Session {
user: {
id: string;
email: string;
name: string;
authMethod: string; // Add authMethod to the session user type
};
}
interface User {
id: string;
email: string;
name: string;
authMethod: string; // Add authMethod to the user type
}
}
+8744
View File
File diff suppressed because it is too large Load Diff
+4 -4
View File
@@ -11,7 +11,7 @@
"dependencies": {
"@auth/prisma-adapter": "^2.4.1",
"@hookform/resolvers": "^3.9.1",
"@prisma/client": "^5.21.1",
"@prisma/client": "^5.22.0",
"@radix-ui/react-accordion": "^1.2.1",
"@radix-ui/react-alert-dialog": "^1.1.2",
"@radix-ui/react-aspect-ratio": "^1.1.0",
@@ -56,9 +56,9 @@
"next-intl": "^3.24.0",
"next-safe-action": "^7.4.3",
"next-themes": "^0.3.0",
"react": "19.0.0-rc-66855b96-20241106",
"react": "^18",
"react-day-picker": "^8.10.1",
"react-dom": "19.0.0-rc-66855b96-20241106",
"react-dom": "^18",
"react-hook-form": "^7.53.1",
"react-resizable-panels": "^2.1.6",
"react-twc": "^1.4.2",
@@ -76,7 +76,7 @@
"eslint": "^8",
"eslint-config-next": "15.0.3",
"postcss": "^8",
"prisma": "^5.21.1",
"prisma": "^5.22.0",
"tailwindcss": "^3.4.1",
"typescript": "^5"
},
@@ -0,0 +1,46 @@
-- CreateEnum
CREATE TYPE "Status" AS ENUM ('waiting', 'ongoing', 'failed', 'success');
-- CreateTable
CREATE TABLE "Agent" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT,
"last_contact" TIMESTAMP(3),
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Agent_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Database" (
"id" TEXT NOT NULL,
"agent_id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT,
"backup_policy" TEXT,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Database_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Backup" (
"id" TEXT NOT NULL,
"database_id" TEXT NOT NULL,
"status" "Status" NOT NULL DEFAULT 'waiting',
"file" TEXT,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Backup_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Restore" (
"id" TEXT NOT NULL,
"backup_id" TEXT NOT NULL,
"status" "Status" NOT NULL DEFAULT 'waiting',
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Restore_pkey" PRIMARY KEY ("id")
);
+5 -5
View File
@@ -62,11 +62,11 @@ model User {
role String?
password String?
accounts Account[]
sessions Session[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")
accounts Account[]
sessions Session[]
authMethod String?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")
@@map("users")
}
+25 -1
View File
@@ -52,6 +52,7 @@ export const {handlers, auth: baseAuth, signIn, signOut} = NextAuth({
name: profile.name,
email: profile.email,
image: profile.picture,
authMethod: "google",
}
},
})
@@ -66,8 +67,31 @@ export const {handlers, auth: baseAuth, signIn, signOut} = NextAuth({
callbacks: {
session({session, user, token}) {
// session.user.role = user.role
// session.user.authMethod = user.authMethod;
return session
}
},
async signIn({ account, user }) {
console.log(account)
// const authMethod = account.provider === 'credentials' ? 'credentials' : 'oauth';
user = await prisma.user.findFirst({
where: {
email: user.email,
}
})
if (!user) {
return true
}
console.log(user)
// Update the user in the database with the auth method
await prisma.user.update({
where: { id: user.id },
data: {
authMethod: account.provider
},
});
return true;
},
},
});
@@ -13,27 +13,31 @@ import {
} from "lucide-react";
import {LoggedInButton} from "@/components/wrappers/Dashboard/LoggedInButton/LoggedInButton";
import {SidebarMenuCustom} from "@/components/wrappers/Dashboard/SideBar/SideBarMenu/SideBarMenu";
import Image from 'next/image';
export function AppSidebar() {
return (
<Sidebar collapsible="icon">
<SidebarHeader>
<div className="flex justify-center items-center ">
<h1 className="font-bold text-xl">Portabase</h1>
</div>
<SidebarMenu>
<SidebarMenuItem>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<SidebarMenuButton>
Select Workspace
Select Project
<ChevronDown className="ml-auto"/>
</SidebarMenuButton>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-[--radix-popper-anchor-width]">
<DropdownMenuItem>
<span>Acme Inc</span>
<span>Project 1</span>
</DropdownMenuItem>
<DropdownMenuItem>
<span>Acme Corp.</span>
<span>Project 2</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
@@ -54,6 +58,9 @@ export function AppSidebar() {
<LoggedInButton/>
</SidebarMenuItem>
</SidebarMenu>
<div className="text-center">
<h1 className="text-[10px]">Portabase Community Edition 1.0.0</h1>
</div>
</SidebarFooter>
</Sidebar>
)