added oauth Route
This commit is contained in:
24
apps/hub/app/(auth)/oauth/_components/action.ts
Normal file
24
apps/hub/app/(auth)/oauth/_components/action.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
'use server';
|
||||
import { getServerSession } from '../../../api/auth/[...nextauth]/auth';
|
||||
import { Service } from '../page';
|
||||
import { PrismaClient } from '@repo/db';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export const generateToken = async (service: Service) => {
|
||||
const session = await getServerSession();
|
||||
if (!session) return null;
|
||||
|
||||
const accessToken = Array.from({ length: 10 }, () =>
|
||||
Math.floor(Math.random() * 10)
|
||||
).join('');
|
||||
|
||||
const code = await prisma.oAuthToken.create({
|
||||
data: {
|
||||
clientId: service.id,
|
||||
userId: session.user.id,
|
||||
accessToken: accessToken,
|
||||
},
|
||||
});
|
||||
return code;
|
||||
};
|
||||
Reference in New Issue
Block a user