added chron to hub server, removed starterEvent
This commit is contained in:
@@ -1,26 +1,8 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getServerSession } from "../auth/[...nextauth]/auth";
|
||||
import { prisma } from "@repo/db";
|
||||
import { generateToken } from "../../(auth)/oauth/_components/action";
|
||||
import { decode, verify } from "jsonwebtoken";
|
||||
|
||||
export async function middleware(req: NextRequest) {
|
||||
const authHeader = req.headers.get("authorization");
|
||||
|
||||
if (authHeader?.startsWith("Bearer ")) {
|
||||
const token = authHeader.split(" ")[1];
|
||||
|
||||
if (token) {
|
||||
// Hier kannst du den Token validieren (optional)
|
||||
|
||||
req.headers.set("x-next-auth-token", token);
|
||||
}
|
||||
|
||||
// Falls NextAuth keine Session hat, erstellen wir eine Fake-Session
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
import { verify } from "jsonwebtoken";
|
||||
import { getMoodleUserById } from "../../../helper/moodle";
|
||||
import { inscribeToMoodleCourse } from "../../(app)/events/actions";
|
||||
|
||||
export const GET = async (req: NextRequest) => {
|
||||
// This route is only used by Moodle, so NextAuth is not used here
|
||||
@@ -39,6 +21,42 @@ export const GET = async (req: NextRequest) => {
|
||||
id: decoded.id,
|
||||
},
|
||||
});
|
||||
if (!user)
|
||||
return NextResponse.json({ error: "User not found" }, { status: 404 });
|
||||
|
||||
setTimeout(async () => {
|
||||
const moodleUser = await getMoodleUserById(user.id);
|
||||
prisma.user.update({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
data: {
|
||||
moodleId: moodleUser?.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (user.moodleId) return;
|
||||
|
||||
const participatingEvents = await prisma.participant.findMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
Event: {
|
||||
finisherMoodleCourseId: {
|
||||
not: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
Event: true,
|
||||
},
|
||||
});
|
||||
participatingEvents.forEach(async (p) => {
|
||||
await inscribeToMoodleCourse(
|
||||
p.Event.finisherMoodleCourseId!,
|
||||
moodleUser?.id,
|
||||
);
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
return NextResponse.json({
|
||||
...user,
|
||||
|
||||
Reference in New Issue
Block a user