aboutsummaryrefslogtreecommitdiff
path: root/pages/testing.js
blob: cae165a31677fdf80a4a444324d71100e069e1f8 (plain) (blame)
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
import { getUser } from "./api/get-user";
import { useSession, signIn } from "next-auth/react";

export default function Testing({ user }) {
  const { data: session } = useSession();
  async function handleUpdate() {
    const lastPlayed = {
      id: "apahisya",
      time: 812989929,
    };
    const res = await fetch("/api/watched-episode", {
      method: "POST",
      body: JSON.stringify({
        username: session?.user.name,
        id: 150672,
        newData: lastPlayed,
      }),
      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(user.settings);
  return (
    <div>
      <button onClick={() => handleUpdate()}>Click for update</button>
      {!session && (
        <button onClick={() => signIn("AniListProvider")}>LOGIN</button>
      )}
    </div>
  );
}

export async function getServerSideProps(context) {
  const user = await getUser("Factiven");
  console.log(user);
  return {
    props: {
      user: user,
    },
  };
}