mirror of
https://github.com/Fayorg/calendrier-avant.git
synced 2026-05-27 17:18:38 +02:00
add: authentication WIP
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
import prisma from '@/lib/prisma';
|
||||
import ActiveCard from './ActiveCard';
|
||||
import { getAuthServerSession } from '@/lib/authenticate';
|
||||
import { red } from 'next/dist/lib/picocolors';
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
export default async function Dashboard() {
|
||||
const authSession = await getAuthServerSession();
|
||||
console.log(authSession);
|
||||
if (!authSession || !authSession.user.isTeacher) return redirect('/');
|
||||
|
||||
const tests = await prisma.test.findMany({ select: { isActive: true, isPassed: true, id: true, testOf: { select: { id: true, firstName: true, lastName: true, isTeacher: true } } } });
|
||||
|
||||
const activeTests = tests.filter((test) => test.isActive);
|
||||
const passedTests = tests.filter((test) => test.isPassed);
|
||||
|
||||
const authSession = await getAuthServerSession();
|
||||
|
||||
console.log(authSession);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Dashboard</h1>
|
||||
|
||||
@@ -5,9 +5,9 @@ import { useRouter } from 'next/navigation';
|
||||
import { useState, useEffect } from 'react';
|
||||
import useSWR from 'swr';
|
||||
import { fetcher } from '@/lib/fetcher';
|
||||
import Image from "next/image";
|
||||
import Logo from "/images/logo.svg";
|
||||
import LogOut from "@images/logout.svg";
|
||||
import Image from 'next/image';
|
||||
import Logo from '/images/logo.svg';
|
||||
import LogOut from '@images/logout.svg';
|
||||
|
||||
export default function Play() {
|
||||
const router = useRouter();
|
||||
@@ -15,17 +15,17 @@ export default function Play() {
|
||||
|
||||
const { data, error, isLoading } = useSWR('/api/test?key=' + password, fetcher);
|
||||
|
||||
useEffect(() => {
|
||||
const pass = localStorage.getItem('@password');
|
||||
setPassword(pass);
|
||||
if (!pass) {
|
||||
router.push('/');
|
||||
}
|
||||
}, [router]);
|
||||
// useEffect(() => {
|
||||
// const pass = localStorage.getItem('@password');
|
||||
// setPassword(pass);
|
||||
// if (!pass) {
|
||||
// router.push('/');
|
||||
// }
|
||||
// }, [router]);
|
||||
|
||||
return (
|
||||
<div className={"w-full h-[100vh] text-[#F0F0F0] bg-black p-12 flex flex-col items-center justify-center gap-y-28"}>
|
||||
<Image src={Logo} alt={"Logo"} width={100} height={200} className={"mx-auto w-full md:w-[400px]"}/>
|
||||
<div className={'w-full h-[100vh] text-[#F0F0F0] bg-black p-12 flex flex-col items-center justify-center gap-y-28'}>
|
||||
<Image src={Logo} alt={'Logo'} width={100} height={200} className={'mx-auto w-full md:w-[400px]'} />
|
||||
<TestCard data={data} error={error} isLoading={isLoading} />
|
||||
{data && data.status == 200 && password && <GradingForm password={password} data={data} />}
|
||||
<div>
|
||||
@@ -35,7 +35,7 @@ export default function Play() {
|
||||
router.push('/');
|
||||
}}
|
||||
>
|
||||
<Image src={LogOut} alt={"Logo"} width={50} height={50} className={"mx-auto w-full md:w-[400px]"}/>
|
||||
<Image src={LogOut} alt={'Logo'} width={50} height={50} className={'mx-auto w-full md:w-[400px]'} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user