"use server";
import { generateUUID } from "../../../../helper/uuid";
import { getServerSession } from "../../../api/auth/[...nextauth]/auth";
import { Service } from "../page";
import { prisma } from "@repo/db";

export const generateToken = async (service: Service) => {
	const session = await getServerSession();
	if (!session) return null;

	const accessToken = generateUUID(16);

	const code = await prisma.oAuthToken.create({
		data: {
			clientId: service.id,
			userId: session.user.id,
			accessToken: accessToken,
		},
	});
	return code;
};
