mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Redirect if user does not exist.
This commit is contained in:
@@ -1,13 +1,18 @@
|
|||||||
import {LayoutAdmin} from "@/components/layout";
|
import {LayoutAdmin} from "@/components/layout";
|
||||||
import Image from 'next/image';
|
import {currentUser} from "@/auth/current-user";
|
||||||
import {currentUser, requiredCurrentUser} from "@/auth/current-user";
|
|
||||||
import {redirect} from "next/navigation";
|
import {redirect} from "next/navigation";
|
||||||
|
import {prisma} from "@/prisma";
|
||||||
|
|
||||||
export default async function Layout({children}: { children: React.ReactNode }) {
|
export default async function Layout({children}: { children: React.ReactNode }) {
|
||||||
|
|
||||||
const user = await currentUser()
|
const user = await currentUser()
|
||||||
|
const userInfo = await prisma.user.findUnique({
|
||||||
|
where: {
|
||||||
|
email: user.email
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
if(user){
|
if(userInfo){
|
||||||
redirect('/dashboard')
|
redirect('/dashboard')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,12 +5,20 @@ import {SidebarInset, SidebarProvider} from "@/components/ui/sidebar"
|
|||||||
import {AppSidebar} from "@/components/wrappers/Dashboard/SideBar/app-sidebar";
|
import {AppSidebar} from "@/components/wrappers/Dashboard/SideBar/app-sidebar";
|
||||||
import {currentUser} from "@/auth/current-user";
|
import {currentUser} from "@/auth/current-user";
|
||||||
import {Header} from "@/features/layout/Header";
|
import {Header} from "@/features/layout/Header";
|
||||||
|
import {prisma} from "@/prisma";
|
||||||
|
|
||||||
|
|
||||||
export default async function Layout({children}: { children: React.ReactNode }) {
|
export default async function Layout({children}: { children: React.ReactNode }) {
|
||||||
|
|
||||||
const user = await currentUser()
|
const user = await currentUser()
|
||||||
if (!user) redirect('/login')
|
|
||||||
|
const userInfo = await prisma.user.findUnique({
|
||||||
|
where: {
|
||||||
|
email: user.email
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!userInfo) redirect('/login')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarProvider>
|
<SidebarProvider>
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the column `authMethod` on the `users` table. All the data in the column will be lost.
|
||||||
|
- You are about to drop the `Restore` table. If the table is not empty, all the data it contains will be lost.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "users" DROP COLUMN "authMethod",
|
||||||
|
ADD COLUMN "auth_method" TEXT;
|
||||||
|
|
||||||
|
-- DropTable
|
||||||
|
DROP TABLE "Restore";
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "Restauration" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"status" "Status" NOT NULL DEFAULT 'waiting',
|
||||||
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"backup_id" TEXT NOT NULL,
|
||||||
|
"database_id" TEXT,
|
||||||
|
|
||||||
|
CONSTRAINT "Restauration_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Backup" ADD CONSTRAINT "Backup_database_id_fkey" FOREIGN KEY ("database_id") REFERENCES "Database"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Restauration" ADD CONSTRAINT "Restauration_backup_id_fkey" FOREIGN KEY ("backup_id") REFERENCES "Backup"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Restauration" ADD CONSTRAINT "Restauration_database_id_fkey" FOREIGN KEY ("database_id") REFERENCES "Database"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
-- CreateEnum
|
||||||
|
CREATE TYPE "TypeStorage" AS ENUM ('local', 's3');
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "Settings" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"storage" "TypeStorage" NOT NULL DEFAULT 'local',
|
||||||
|
"s3AccessKeyId" TEXT,
|
||||||
|
"s3SecretAccessKey" TEXT,
|
||||||
|
"S3BucketName" TEXT,
|
||||||
|
|
||||||
|
CONSTRAINT "Settings_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
@@ -126,3 +126,16 @@ model Restauration {
|
|||||||
databaseId String? @map("database_id")
|
databaseId String? @map("database_id")
|
||||||
database Database? @relation(fields: [databaseId], references: [id], onDelete: Cascade)
|
database Database? @relation(fields: [databaseId], references: [id], onDelete: Cascade)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum TypeStorage {
|
||||||
|
local
|
||||||
|
s3
|
||||||
|
}
|
||||||
|
|
||||||
|
model Settings {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
storage TypeStorage @default(local)
|
||||||
|
s3AccessKeyId String?
|
||||||
|
s3SecretAccessKey String?
|
||||||
|
S3BucketName String?
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import {useMutation} from "@tanstack/react-query";
|
import {useMutation} from "@tanstack/react-query";
|
||||||
import {useRouter} from "next/navigation";
|
|
||||||
import {signOutAction} from "@/features/auth/auth.action";
|
import {signOutAction} from "@/features/auth/auth.action";
|
||||||
import {ButtonWithConfirm} from "@/components/wrappers/Button/ButtonWithConfirm/ButtonWithConfirm";
|
import {ButtonWithConfirm} from "@/components/wrappers/Button/ButtonWithConfirm/ButtonWithConfirm";
|
||||||
import {deleteUserAction} from "@/components/wrappers/Dashboard/Profile/ButtonDeleteAccount/delete-account.action";
|
import {deleteUserAction} from "@/components/wrappers/Dashboard/Profile/ButtonDeleteAccount/delete-account.action";
|
||||||
|
|||||||
Reference in New Issue
Block a user