diff --git a/pages/api/users.ts b/pages/api/users.ts
index 618b38e..1588245 100644
--- a/pages/api/users.ts
+++ b/pages/api/users.ts
@@ -1,13 +1,19 @@
import type { NextApiRequest, NextApiResponse } from "next";
+import { getSession } from "next-auth/react";
+import { MongoClient } from "mongodb";
+
+const client = new MongoClient(process.env.MONGODB_URI || "");
export default async (req: NextApiRequest, res: NextApiResponse) => {
- try {
- const response = await fetch("https://api.medina.dev/v1/usernames");
- const usernames = await response.json();
- res.send(usernames);
- } catch (e) {
- res.send({
- error: e
- })
- }
+ const session = await getSession({ req });
+ if (!session) {
+ return res.status(404).send({
+ message: "Not logged in",
+ });
+ }
+
+ await client.connect();
+ let db = await client.db("auth");
+ let users = await db.collection("users").find().toArray();
+ return res.status(200).send(users);
};
diff --git a/pages/user/[id].tsx b/pages/user/[id].tsx
new file mode 100644
index 0000000..4cdccb1
--- /dev/null
+++ b/pages/user/[id].tsx
@@ -0,0 +1,93 @@
+import React, { useEffect } from "react";
+import { useRouter } from "next/router";
+import Head from "next/head";
+import Navbar from "../../components/Navbar";
+import { MongoClient } from "mongodb";
+import { getSession } from "next-auth/react";
+import { GetServerSideProps, GetServerSidePropsContext } from "next";
+
+type Props = {
+ message: string;
+ user: {
+ name: string;
+ email: string;
+ image: string;
+ bio: string;
+ };
+};
+
+const User = ({ message, user, error }: Props) => {
+ console.log(message, user);
+ const router = useRouter();
+ const { id } = router.query;
+
+ return (
+ <>
+
{user.bio || "No bio yet..."}
+