Skip to content

Commit

Permalink
feat: add user class (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement-Muth authored Jul 11, 2023
1 parent 1159b42 commit cc44db4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import { getServerSession } from "next-auth";
import { Balancer } from "react-wrap-balancer";
import { authOptions } from "~/app/api/auth/[...nextauth]/route";
import getUser from "~/applications/Authentication/Api/getUser";
import UnsignedHome from "~/views/Home/UnsignedHome";

const HomePage = async () => {
return (
<>
<Balancer
as="h1"
className="bg-gradient-to-br from-black to-stone-500 bg-clip-text text-center font-display text-4xl font-bold tracking-[-0.02em] drop-shadow-sm md:text-7xl md:leading-[5rem]"
>
PComparator Compare prices of many products
</Balancer>
<Balancer as="p" className="mt-6 text-center text-gray-500 md:text-xl">
PriceComparator is the price comparator for foods, cosmetic and more
</Balancer>
</>
);
const user = await getUser();

return user.exist ? <h1>Hello {user.user?.name}</h1> : <UnsignedHome />;
};

export default HomePage;
12 changes: 12 additions & 0 deletions src/applications/Authentication/Api/getUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getServerSession } from "next-auth";
import { authOptions } from "~/app/api/auth/[...nextauth]/route";
import { User } from "~/applications/Authentication/Domain/User";

const getUser = async () => {
const session = await getServerSession(authOptions);
const user = new User(session?.user);

return user;
};

export default getUser;
19 changes: 19 additions & 0 deletions src/applications/Authentication/Domain/User.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Session } from "next-auth";

type UserProfile = {
email?: string | null | undefined;
name?: string | null | undefined;
image?: string | null | undefined;
};

export class User {
public readonly user: UserProfile | undefined;

constructor(user: Session["user"]) {
this.user = user;
}

get exist(): boolean {
return !!this.user ?? false;
}
}
19 changes: 19 additions & 0 deletions src/views/Home/UnsignedHome.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Balancer } from "react-wrap-balancer";

const UnsignedHome = () => {
return (
<>
<Balancer
as="h1"
className="bg-gradient-to-br from-black to-stone-500 bg-clip-text text-center font-display text-4xl font-bold tracking-[-0.02em] drop-shadow-sm md:text-7xl md:leading-[5rem]"
>
PComparator Compare prices of many products
</Balancer>
<Balancer as="p" className="mt-6 text-center text-gray-500 md:text-xl">
PriceComparator is the price comparator for foods, cosmetic and more
</Balancer>
</>
);
};

export default UnsignedHome;

0 comments on commit cc44db4

Please sign in to comment.