Skip to content

Commit

Permalink
✨ Fixed issues with profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
dnrm committed Jun 14, 2023
1 parent b2adb3e commit eea0c31
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 45 deletions.
Binary file added images/germany.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import Head from "next/head";
import Image from "next/image";
import Image from "next/legacy/image";
import src from "../images/trees.jpeg";

const NotFound = () => {
Expand Down Expand Up @@ -28,7 +28,7 @@ const NotFound = () => {
</h1>
</header>
<section>
<Image src={src} layout="responsive" />
<Image alt="Not found" src={src} layout="responsive" />
</section>
</main>
);
Expand Down
4 changes: 2 additions & 2 deletions pages/500.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import Head from "next/head";
import Image from "next/image";
import Image from "next/legacy/image";
import src from "../images/trees.jpeg";

const ServerError = () => {
Expand Down Expand Up @@ -28,7 +28,7 @@ const ServerError = () => {
</h1>
</header>
<section>
<Image src={src} layout="responsive" />
<Image alt="IDK" src={src} layout="responsive" />
</section>
</main>
);
Expand Down
62 changes: 34 additions & 28 deletions pages/api/update-user.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { getSession } from "next-auth/react";
import { getServerSession } from "next-auth/next";
import { MongoClient } from "mongodb";
import { authOptions } from "./auth/[...nextauth]";

const client = new MongoClient(process.env.MONGODB_URI || "");

export default async (req: NextApiRequest, res: NextApiResponse) => {
const session = await getSession({ req });
if (!session || !req.body.username) {
return res.status(400).send({
error:
"You're missing to log in or to provide the username to set.",
});
}
const session = await getServerSession(req, res, authOptions);
if (!session || !req.body.username) {
return res.status(400).send({
error: "You're missing to log in or to provide the username to set.",
});
}

if (!req.body.username.match(/^[a-zA-Z0-9_]+$/)) {
return res.status(400).send({
error: "The username use only letters, numbers and underscores.",
})
} else if (req.body.username.length > 21) {
return res.status(400).send({
error: "The username must be between 1 and 21 characters long.",
})
}
if (!req.body.username.match(/^[a-zA-Z0-9_]+$/)) {
return res.status(400).send({
error: "The username use only letters, numbers and underscores.",
});
} else if (req.body.username.length > 21) {
return res.status(400).send({
error: "The username must be between 1 and 21 characters long.",
});
}

console.log(req.body);
console.log(req.body);

const email = session?.user?.email;
await client.connect();
let db = await client.db("auth");
let doc = await db
.collection("users")
.findOneAndUpdate(
{ email },
{ $set: { username: req.body.username, name: req.body.name, bio: req.body.bio } }
);
return res.status(200).send(doc);
const email = session?.user?.email;
await client.connect();
let db = await client.db("auth");
let doc = await db
.collection("users")
.findOneAndUpdate(
{ email },
{
$set: {
username: req.body.username,
name: req.body.name,
bio: req.body.bio,
},
}
);
return res.status(200).send(doc);
};
26 changes: 13 additions & 13 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Link from "next/link";
import Footer from "../components/Footer";
import Navbar from "../components/Navbar";
import { useSession } from "next-auth/react";
import src from "../images/desert.jpeg";
import src from "../images/germany.jpg";
import { usePostsContext } from "../context/posts";
import Post from "../components/Post";
import { PostType } from "../types/Post";
Expand Down Expand Up @@ -66,18 +66,18 @@ export default function Home() {
)}
</div>
</header>
<section>
<Image
src={src}
alt="Cover image"
width="100"
height="38"
className="object-cover"
layout="responsive"
priority={true}
placeholder="blur"
blurDataURL={"/desert.jpeg"}
/>
<section className="max-h-screen h-[75vh] w-full">
<div className="relative h-full w-full">
<Image
src={src}
alt="Cover image"
className="object-cover"
fill
priority={true}
placeholder="blur"
blurDataURL={"/germany.jpeg"}
/>
</div>
</section>
<section id="posts" className="max-w-6xl mx-auto">
<h1 className="text-4xl md:text-6xl lg:text-8xl tracking-tighter font-bold text-black pt-8 pb-2">
Expand Down

0 comments on commit eea0c31

Please sign in to comment.