Skip to content

Commit cb6d58f

Browse files
authored
Merge pull request #40 from thidkyar/6-login-capabilities
#6 Login Capabilities
2 parents f1a8f84 + c418bb1 commit cb6d58f

File tree

5 files changed

+61
-12
lines changed

5 files changed

+61
-12
lines changed

.env.example

+8-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
DATABASE_URL="postgresql://postgres:example@localhost:5432/postgres"
1+
DATABASE_URL="postgresql://postgres:example@localhost:5432/postgres"
2+
3+
# Next Auth Discord Provider
4+
GITHUB_CLIENT_ID=""
5+
GITHUB_CLIENT_SECRET=""
6+
7+
NEXTAUTH_SECRET="my_ultra_secure_nextauth_secret"
8+
NEXTAUTH_URL="http://localhost:3000"

next.config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = {}
2+
const nextConfig = {
3+
images: { domains: ['avatars.githubusercontent.com'] }
4+
}
35

46
module.exports = nextConfig

src/app/api/auth/[...nextauth]/route.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import GithubProvider from "next-auth/providers/github";
44
const handler = NextAuth({
55
providers: [
66
GithubProvider({
7-
clientId: "setup-with-community",
8-
clientSecret: "setup-with-community",
7+
clientId: process.env.GITHUB_CLIENT_ID!,
8+
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
99
}),
1010
],
1111
});

src/app/page.tsx

+28-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
import { Button } from "@/components/ui/button";
2+
import { LoginButton, LogoutButton } from "@/components/ui/buttons";
23
import { prisma } from "@/lib/prisma";
4+
import { getServerSession } from "next-auth";
5+
import Image from "next/image";
36

47
export default async function Home() {
5-
const users = await prisma.user.findMany();
6-
console.log(users);
7-
8-
return (
9-
<main className="flex min-h-screen flex-col items-center justify-between p-24">
10-
<Button>Button</Button>
11-
</main>
12-
);
8+
const users = await prisma.user.findMany();
9+
console.log(users);
10+
const session = await getServerSession();
11+
return (
12+
<main className="flex min-h-screen flex-col items-center justify-between p-24">
13+
<Button>Button</Button>
14+
{session ? (
15+
<div className="flex space-x-2 items-center">
16+
<Image
17+
className="rounded-full"
18+
src={session?.user?.image!}
19+
alt="user avatar"
20+
height={40}
21+
width={40}
22+
/>
23+
<p className="text-gray-700 font-bold">
24+
{session?.user?.name}
25+
</p>
26+
<LogoutButton />
27+
</div>
28+
) : (
29+
<LoginButton />
30+
)}
31+
</main>
32+
);
1333
}

src/components/ui/buttons.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use client";
2+
3+
import { signIn, signOut } from "next-auth/react";
4+
import { Button } from "./button";
5+
6+
export const LoginButton = () => {
7+
return (
8+
<Button onClick={() => signIn()}>
9+
Sign in
10+
</Button>
11+
);
12+
};
13+
14+
export const LogoutButton = () => {
15+
return (
16+
<Button onClick={() => signOut()}>
17+
Sign Out
18+
</Button>
19+
);
20+
};

0 commit comments

Comments
 (0)