Correcting some bugs in statistics.

This commit is contained in:
charles-gauthereau
2025-02-13 19:20:55 +01:00
parent 7a59c616eb
commit 8586abf7e5
8 changed files with 81 additions and 33 deletions
+1 -16
View File
@@ -1,24 +1,9 @@
import React from "react";
import {LayoutAdmin} from "@/components/layout";
import {currentUser} from "@/auth/current-user";
import {redirect} from "next/navigation";
import {prisma} from "@/prisma";
export default async function Layout({children}: { children: React.ReactNode }) {
const user = await currentUser()
if(user){
const userInfo = await prisma.user.findUnique({
where: {
email: user?.email
}
})
if(userInfo && userInfo.authMethod){
redirect('/')
// redirect('/dashboard')
}
}
return (
<LayoutAdmin>
@@ -0,0 +1,20 @@
import React from "react";
import {getCurrentOrganizationSlug} from "@/features/dashboard/organization-cookie";
import {notFound, redirect} from "next/navigation";
export default async function Layout({children, params}: { children: React.ReactNode , params: { slug: string };}) {
const {slug: organizationSlug} = await params
console.log(organizationSlug);
const currentOrganizationSlug = await getCurrentOrganizationSlug()
console.log(currentOrganizationSlug);
if(currentOrganizationSlug != organizationSlug) {
redirect("charles")
}
return (
<>
{children}
</>
)
}
@@ -0,0 +1,26 @@
import {redirect, useRouter} from "next/navigation";
import {useEffect} from "react";
import {currentUser} from "@/auth/current-user";
// export default function NotFound() {
//
// const router = useRouter();
//
// useEffect(() => {
// router.push('/');
// }, [router]);
//
// return null; // You can return null or a loading spinner while the redirect happens
// }
export default async function NotFound() {
// const user = await currentUser()
// if (!user) {
// redirect("/")
// }else{
// redirect("/")
// }
redirect("/dashboard/default")
}
@@ -6,22 +6,19 @@ import {CardsWithPagination} from "@/components/wrappers/common/cards-with-pagin
import {Button} from "@/components/ui/button";
import {Page, PageActions, PageContent, PageHeader, PageTitle} from "@/features/layout/page";
import {ProjectCard} from "@/components/wrappers/dashboard/projects/ProjectCard/ProjectCard";
import {requiredCurrentUser} from "@/auth/current-user";
import {getCurrentOrganizationSlug} from "@/features/dashboard/organization-cookie";
import {currentOrganization} from "@/auth/current-organization";
import {notFound} from "next/navigation";
export default async function RoutePage(props: PageParams<{slug: string}>) {
const {slug: organizationSlug} = await props.params
const user = await requiredCurrentUser()
const currentOrganizationSlug = await getCurrentOrganizationSlug()
if(currentOrganizationSlug != organizationSlug) {
notFound()
}
// if(currentOrganizationSlug != organizationSlug) {
// notFound()
// }
const projects = await prisma.project.findMany({
where: {
-1
View File
@@ -6,7 +6,6 @@ import {AppSidebar} from "@/components/wrappers/dashboard/sideBar/app-sidebar";
import {currentUser} from "@/auth/current-user";
import {Header} from "@/features/layout/Header";
import {prisma} from "@/prisma";
import {GlobalStoreProvider} from "@/state-management/provider";
export default async function Layout({children}: { children: React.ReactNode }) {
+1 -1
View File
@@ -7,7 +7,7 @@ export default async function Index() {
const user = await currentUser()
if (user) {
const currentOrganizationSlug = await getCurrentOrganizationSlug()
console.log(currentOrganizationSlug)
redirect(`/dashboard/${currentOrganizationSlug}/projects`)
}
redirect("/login")
+20 -8
View File
@@ -1,14 +1,26 @@
"use client"
import {useRouter} from "next/navigation";
import {redirect, useRouter} from "next/navigation";
import {useEffect} from "react";
import {currentUser} from "@/auth/current-user";
export default function NotFound() {
// export default function NotFound() {
//
// const router = useRouter();
//
// useEffect(() => {
// router.push('/');
// }, [router]);
//
// return null; // You can return null or a loading spinner while the redirect happens
// }
const router = useRouter();
export default async function NotFound() {
useEffect(() => {
router.push('/');
}, [router]);
// const user = await currentUser()
// if (!user) {
// redirect("/")
// }else{
// redirect("/")
// }
return null; // You can return null or a loading spinner while the redirect happens
redirect("/")
}
+10 -1
View File
@@ -1,6 +1,7 @@
"use server"
import {baseAuth} from "@/auth/auth";
import {User} from "@prisma/client";
import {prisma} from "@/prisma";
export const currentUser = async () => {
const session = await baseAuth();
@@ -14,7 +15,15 @@ export const currentUser = async () => {
export const requiredCurrentUser = async () => {
const user = await currentUser();
if (!user) {
throw new Error("User not found");
return null
}
const userDb = await prisma.user.findFirst({
where: {id: user.id},
})
if(!userDb){
return null
}
return user;
}