1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
import { signIn, signOut, useSession } from "next-auth/react";
import { getServerSession } from "next-auth/next";
import { authOptions } from "./api/auth/[...nextauth]";
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || "http://localhost:3000";
export default function Testing({ sesi, data, progress, statusWatch }) {
const { data: session, status } = useSession();
// console.log(session.user.id);
async function handleUpdate() {
// const data = ;
const res = await fetch("/api/update-user", {
method: "POST",
body: JSON.stringify({
name: session?.user.name,
newData: {
recentWatch: {
id: parseInt(9280220),
title: {
romaji: "something title here",
},
description:
"lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quod.",
coverImage: {
extraLarge: "this should be an image url",
},
episode: {
id: "first-id-yeah",
time: 12344,
},
},
},
}),
headers: {
"Content-Type": "application/json",
},
});
// const data = await res.json(); // parse the response body as JSON
// console.log(data.dat.id);
console.log(res.status);
}
console.log(statusWatch);
return (
<div>
<button onClick={() => handleUpdate()}>Click for update</button>
{!session && (
<button onClick={() => signIn("AniListProvider")}>LOGIN</button>
)}
{session && <button onClick={() => signOut()}>LOGOUT</button>}
</div>
);
}
export async function getServerSideProps(context) {
const session = await getServerSession(context.req, context.res, authOptions);
const res = await fetch(`${baseUrl}/api/get-media`, {
method: "POST",
body: JSON.stringify({
username: session?.user.name,
}),
headers: {
"Content-Type": "application/json",
},
});
const prog = await res.json();
const gat = prog.lists.map((item) => item.entries);
const git = gat.map((item) => item.find((item) => item.media.id === 130003));
const gut = git.find((item) => item?.media.id === 130003);
let progress = null;
let statusWatch = "CURRENT";
if (gut?.status === "COMPLETED") {
statusWatch = "REPEATING";
}
if (gut) {
progress = gut?.progress;
}
return {
props: {
sesi: session,
data: gut || null,
progress: progress,
statusWatch: statusWatch,
},
};
}
|