Skip to content

Commit 23a0fbd

Browse files
committed
update Fred
1 parent 8bdbcb3 commit 23a0fbd

File tree

8 files changed

+266
-1
lines changed

8 files changed

+266
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ yarn-error.log*
2727

2828
# local env files
2929
.env*.local
30+
.env
3031

3132
# vercel
3233
.vercel

jsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"compilerOptions": {
3+
"jsx": "react",
34
"paths": {
45
"@/*": ["./src/*"]
56
}

package-lock.json

Lines changed: 188 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
},
1111
"dependencies": {
1212
"next": "^14.2.4",
13+
"next-auth": "^4.24.7",
1314
"react": "^18",
1415
"react-dom": "^18",
1516
"web-vitals": "^4.2.1"
17+
},
18+
"devDependencies": {
19+
"@types/node": "^20.14.10"
1620
}
1721
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// imports
2+
import NextAuth from "next-auth"
3+
4+
// importing providers
5+
import GithubProvider from "next-auth/providers/github"
6+
import GoogleProvider from "next-auth/providers/google";
7+
8+
const handler = NextAuth({
9+
providers: [
10+
GithubProvider({
11+
clientId: process.env.GITHUB_ID,
12+
clientSecret: process.env.GITHUB_SECRET,
13+
}),
14+
GoogleProvider({
15+
clientId: process.env.GOOGLE_CLIENT_ID,
16+
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
17+
})
18+
]
19+
})
20+
21+
export { handler as GET, handler as POST }

src/app/components/SessionWrapper.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// mark as client component
2+
"use client";
3+
import { SessionProvider } from "next-auth/react";
4+
import React from 'react';
5+
6+
const SessionWrapper = ({ children }) => {
7+
return (
8+
<SessionProvider>
9+
{children}
10+
</SessionProvider>
11+
);
12+
}
13+
14+
export default SessionWrapper;

src/app/layout.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import "./globals.css";
44
// import { WebVitals } from './_components/web-vitals';
55
// import { NextWebVitals } from "nextlevelpackage";
66

7+
import SessionWrapper from './components/SessionWrapper'
8+
79
const inter = Inter({ subsets: ["latin"] });
810

911
export const metadata = {
@@ -13,10 +15,13 @@ export const metadata = {
1315

1416
export default function RootLayout({ children }) {
1517
return (
16-
<html lang="en">
18+
<SessionWrapper>
19+
<html lang="en">
1720
<body className={inter.className}>
1821
{children}
1922
</body>
2023
</html>
24+
</SessionWrapper>
25+
2126
);
2227
}

src/app/login/login.jsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use client";
2+
3+
// importing necessary functions
4+
import { useSession, signIn, signOut } from "next-auth/react";
5+
import Image from "next/image";
6+
7+
export default function Home() {
8+
// extracting data from usesession as session
9+
const { data: session } = useSession();
10+
11+
// checking if sessions exists
12+
if (session) {
13+
// rendering components for logged-in users
14+
return (
15+
<>
16+
<p>Welcome {session.user.name}. Signed In As</p>
17+
<p>{session.user.email}</p>
18+
<button onClick={() => signOut()}>Sign out</button>
19+
</>
20+
);
21+
}
22+
23+
// rendering components for not logged-in users
24+
return (
25+
<>
26+
<p>Not Signed In</p>
27+
<button onClick={() => signIn('google')}>Sign in with Google</button>
28+
<button onClick={() => signIn('github')}>Sign in with GitHub</button>
29+
</>
30+
);
31+
}

0 commit comments

Comments
 (0)