Added redemptions & redeemable actions. Fixed a few bugs.

This commit is contained in:
Tom
2024-06-24 22:16:55 +00:00
parent 68df045c54
commit 6548ce33e0
35 changed files with 1787 additions and 471 deletions

View File

@ -30,7 +30,6 @@ export async function GET(req: Request, { params } : { params: { id: string } })
export async function DELETE(req: Request, { params } : { params: { id: string } }) {
try {
const user = await fetchUserWithImpersonation(req)
if (!user) {
return new NextResponse("Unauthorized", { status: 401 });
}

View File

@ -4,20 +4,24 @@ import { NextResponse } from "next/server";
export async function GET(req: Request) {
try {
console.log("ABC 1")
const user = await fetchUserWithImpersonation(req);
if (!user) {
return new NextResponse("Unauthorized", { status: 401 });
}
console.log("ABC 2")
const api = await db.twitchConnection.findFirst({
where: {
userId: user.id
}
})
console.log("ABC 3")
if (!api) {
return new NextResponse("Forbidden", { status: 403 });
}
console.log("ABC 4")
const data = {
client_id: process.env.TWITCH_BOT_CLIENT_ID,
client_secret: process.env.TWITCH_BOT_CLIENT_SECRET,
@ -25,6 +29,7 @@ export async function GET(req: Request) {
refresh_token: api.refreshToken,
broadcaster_id: api.broadcasterId
}
console.log("ABC 5", data)
return NextResponse.json(data);
} catch (error) {
console.log("[TOKENS/GET]", error);

View File

@ -20,11 +20,11 @@ export async function POST(req: Request) {
const id = generateToken()
const token = await db.apiKey.create({
data: {
id,
label,
userId: userId as string
}
data: {
id,
label,
userId: userId as string
}
});
return NextResponse.json(token);
@ -41,16 +41,16 @@ export async function DELETE(req: Request) {
return new NextResponse("Unauthorized", { status: 401 });
}
let { id } = await req.json();
const { id } = await req.json();
if (!id) {
return NextResponse.json(null)
}
const token = await db.apiKey.delete({
where: {
id,
userId: user?.id
}
where: {
id,
userId: user?.id
}
});
return NextResponse.json(token);
@ -60,12 +60,12 @@ export async function DELETE(req: Request) {
}
}
export function generateToken() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 32;
var randomstring = '';
for (var i = 0; i < string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
function generateToken() {
let chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
let string_length = 32;
let randomstring = '';
for (let i = 0; i < string_length; i++) {
let rnum = Math.floor(Math.random() * chars.length);
randomstring += chars[rnum];
}
return randomstring;