Upgraded to Next Auth v5

This commit is contained in:
Tom
2024-01-02 07:26:20 +00:00
parent a3352af981
commit 4505654a05
24 changed files with 283 additions and 227 deletions

View File

@ -9,9 +9,6 @@ export async function GET(req: Request) {
const scope = searchParams.get('scope') as string
const state = searchParams.get('state') as string
console.log("CODE:", code)
console.log("SCOPE:", scope)
console.log("STATE:", state)
if (!code || !scope || !state) {
return new NextResponse("Bad Request", { status: 400 });
}
@ -38,21 +35,17 @@ 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)
if (!access_token || !refresh_token || token_type !== "bearer") {
return new NextResponse("Unauthorized", { status: 401 });
}
let info = await axios.get("https://api.twitch.tv/helix/users?login=" + user.username, {
let info = await axios.get("https://api.twitch.tv/helix/users?login=" + user.name, {
headers: {
"Authorization": "Bearer " + access_token,
"Client-Id": process.env.TWITCH_BOT_CLIENT_ID
}
})
console.log(info.data.data)
const broadcasterId = info.data.data[0]['id']
await db.twitchConnection.create({

View File

@ -1,7 +1,6 @@
import axios from 'axios'
import { db } from "@/lib/db"
import { NextResponse } from "next/server";
import { GET as authorize } from '../authorize/route'
export async function GET(req: Request) {
try {
@ -11,7 +10,6 @@ export async function GET(req: Request) {
id: req.headers.get('x-api-key') as string
}
})
if (!key) {
return new NextResponse("Forbidden", { status: 403 });
}
@ -46,9 +44,6 @@ 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)
if (!access_token || !refresh_token || token_type !== "bearer") {
return new NextResponse("Unauthorized", { status: 401 });

View File

@ -1,7 +1,6 @@
import { db } from "@/lib/db"
import { NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import { generateToken } from "../token/route";
import { auth } from "@/auth";
import fetchUserUsingAPI from "@/lib/validate-api";
@ -16,7 +15,7 @@ export async function GET(req: Request) {
export async function POST(req: Request) {
try {
const session = await getServerSession()
const session = await auth()
const user = session?.user?.name
if (!user) {
return new NextResponse("Internal Error", { status: 401 })
@ -24,26 +23,26 @@ export async function POST(req: Request) {
const exist = await db.user.findFirst({
where: {
username: user.toLowerCase() as string
name: user
}
});
if (exist) {
return NextResponse.json({
id: exist.id,
username: exist.username
username: exist.name
});
}
const newUser = await db.user.create({
data: {
username: user.toLowerCase() as string,
name: user,
}
});
return NextResponse.json({
id: newUser.id,
username: newUser.username
username: newUser.name
});
} catch (error) {
console.log("[ACCOUNT]", error);