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:
Tom
2023-12-31 10:41:55 +00:00
parent 8eb9b9096f
commit a3352af981
20 changed files with 1083 additions and 287 deletions

View File

@ -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 });