Changed settings layout + separated settings into different pages. Cleaned some code. Working on tts pages (no db/rest calls yet).
This commit is contained in:
@ -15,7 +15,7 @@ export async function GET(req: Request) {
|
||||
if (!code || !scope || !state) {
|
||||
return new NextResponse("Bad Request", { status: 400 });
|
||||
}
|
||||
console.log("VERIFY")
|
||||
|
||||
// Verify state against user id in user table.
|
||||
const user = await db.user.findFirst({
|
||||
where: {
|
||||
@ -23,12 +23,10 @@ export async function GET(req: Request) {
|
||||
}
|
||||
})
|
||||
|
||||
console.log("USER", user)
|
||||
if (!user) {
|
||||
return new NextResponse("Bad Request", { status: 400 });
|
||||
}
|
||||
|
||||
console.log("FETCH TOKEN")
|
||||
// Post to https://id.twitch.tv/oauth2/token
|
||||
const token: { access_token:string, expires_in:number, refresh_token:string, token_type:string, scope:string[] } = (await axios.post("https://id.twitch.tv/oauth2/token", {
|
||||
client_id: process.env.TWITCH_BOT_CLIENT_ID,
|
||||
@ -37,13 +35,12 @@ export async function GET(req: Request) {
|
||||
grant_type: "authorization_code",
|
||||
redirect_uri: "https://hermes.goblincaves.com/api/account/authorize"
|
||||
})).data
|
||||
console.log("TOKEN", token)
|
||||
|
||||
// Fetch values from token.
|
||||
const { access_token, expires_in, refresh_token, token_type } = token
|
||||
console.log("AT", access_token)
|
||||
console.log("RT", refresh_token)
|
||||
console.log("TT", token_type)
|
||||
// console.log("AT", access_token)
|
||||
// console.log("RT", refresh_token)
|
||||
// console.log("TT", token_type)
|
||||
|
||||
if (!access_token || !refresh_token || token_type !== "bearer") {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
|
@ -12,7 +12,6 @@ export async function GET(req: Request) {
|
||||
}
|
||||
})
|
||||
|
||||
console.log("API USER:", key)
|
||||
if (!key) {
|
||||
return new NextResponse("Forbidden", { status: 403 });
|
||||
}
|
||||
@ -35,7 +34,6 @@ export async function GET(req: Request) {
|
||||
if (expires_in > 3600)
|
||||
return new NextResponse("", { status: 201 });
|
||||
} catch (error) {
|
||||
console.log("Oudated Twitch token.")
|
||||
}
|
||||
|
||||
// Post to https://id.twitch.tv/oauth2/token
|
||||
@ -48,9 +46,9 @@ export async function GET(req: Request) {
|
||||
|
||||
// Fetch values from token.
|
||||
const { access_token, expires_in, refresh_token, token_type } = token
|
||||
console.log("AT", access_token)
|
||||
console.log("RT", refresh_token)
|
||||
console.log("TT", token_type)
|
||||
// console.log("AT", access_token)
|
||||
// console.log("RT", refresh_token)
|
||||
// console.log("TT", token_type)
|
||||
|
||||
if (!access_token || !refresh_token || token_type !== "bearer") {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
|
@ -29,16 +29,10 @@ export async function POST(req: Request) {
|
||||
});
|
||||
|
||||
if (exist) {
|
||||
// const apikey = await db.apiKey.findFirst({
|
||||
// where: {
|
||||
// userId: user.toLowerCase() as string
|
||||
// }
|
||||
// })
|
||||
return {
|
||||
return NextResponse.json({
|
||||
id: exist.id,
|
||||
username: exist.username,
|
||||
//key: apikey?.id as string
|
||||
};
|
||||
username: exist.username
|
||||
});
|
||||
}
|
||||
|
||||
const newUser = await db.user.create({
|
||||
@ -47,18 +41,9 @@ export async function POST(req: Request) {
|
||||
}
|
||||
});
|
||||
|
||||
// const apikey = await db.apiKey.create({
|
||||
// data: {
|
||||
// id: generateToken(),
|
||||
// label: "Default",
|
||||
// userId: user.toLowerCase() as string
|
||||
// }
|
||||
// })
|
||||
|
||||
return NextResponse.json({
|
||||
id: newUser.id,
|
||||
username: newUser.username,
|
||||
//key: apikey.id
|
||||
username: newUser.username
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("[ACCOUNT]", error);
|
||||
|
@ -37,12 +37,11 @@ export async function POST(req: Request) {
|
||||
try {
|
||||
const { id, secret } = await req.json();
|
||||
const user = await fetchUserUsingAPI(req)
|
||||
console.log("userrr:", user)
|
||||
|
||||
if (!user) {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
}
|
||||
|
||||
console.log(id, secret)
|
||||
let response = null;
|
||||
try {
|
||||
response = await axios.post("https://id.twitch.tv/oauth2/token", {
|
||||
@ -69,7 +68,7 @@ export async function POST(req: Request) {
|
||||
|
||||
const connection = await db.twitchConnection.create({
|
||||
data: {
|
||||
id,
|
||||
id: id,
|
||||
secret,
|
||||
userId: user.id as string,
|
||||
broadcasterId,
|
||||
|
Reference in New Issue
Block a user