Skip to content

Commit 4a78fab

Browse files
ok
1 parent b1036b8 commit 4a78fab

File tree

8 files changed

+115
-12
lines changed

8 files changed

+115
-12
lines changed

.env

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
MONGODB = 'mongodb://127.0.0.1:27017/ryugen'
2-
APP_URL = 'http://localhost:3000'
1+
MONGODB='mongodb://127.0.0.1:27017/ryugen'
2+
APP_URL='http://localhost:3000'
3+
GOOGLE_CLIENT_ID ='416949910262-ifg1peckg8jjmb59hj0ggptb46fvtr0f.apps.googleusercontent.com'
4+
GOOGLE_CLIENT_SECRET='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'
5+
6+
NEXTAUTH_SECRET='ksdandquu329undqdjdnjoladp20i3'
7+
NEXTAUTH_URL='http://localhost:3000'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import NextAuth from "next-auth/next";
2+
import GoogleProvider from "next-auth/providers/google";
3+
4+
const handler = NextAuth ({
5+
providers:[
6+
GoogleProvider({
7+
clientId:process.env.GOOGLE_CLIENT_ID,
8+
clientSecret:process.env.GOOGLE_CLIENT_SECRET,
9+
}),
10+
],
11+
});
12+
13+
14+
export { handler as GET, handler as POST};

src/app/dashboard/(auth)/login/page.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
"use client"
2+
import { signIn } from 'next-auth/react'
13
import React from 'react'
24

35
const Login = () => {
46
return (
5-
<div>Login</div>
7+
<div>
8+
<button onClick={()=>signIn("google")}>Login With Google</button>
9+
</div>
610
)
711
}
812

src/app/dashboard/(auth)/register/page.jsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
1-
import React from 'react'
2-
1+
"use client"
2+
import React,{useState}from 'react'
3+
import styles from './page.module.css'
4+
import Link from 'next/link'
35
const Register = () => {
6+
const handleSumbmit = async (e)=>{
7+
const [err,setErr] = useState(false);
8+
e.preventDefault();
9+
const name = e.target[0].value;
10+
const email = e.target[1].value;
11+
const password = e.target[2].value;
12+
try{
13+
14+
}catch(err){
15+
setErr(true);
16+
}
17+
}
418
return (
5-
<div>Register</div>
19+
<div className={styles.container}>
20+
<form className={styles.form} onSubmit={handleSumbmit}>
21+
<input type="text" placeholder='username' className={styles.input} required/>
22+
<input type="email" placeholder='email' className={styles.input} required/>
23+
<input type="password" placeholder='password' className={styles.input} required/>
24+
<button className={styles.button}>Register</button>
25+
</form>
26+
{err&&"Something went wrong !"}
27+
<Link href="/dashboard/login">Login with an existing account </Link>
28+
</div>
629
)
730
}
831

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.container{
2+
display: flex;
3+
align-items: center;
4+
justify-content: center;
5+
flex-direction: column;
6+
gap: 20px;
7+
}
8+
9+
.form{
10+
width: 300px;
11+
display: flex;
12+
flex-direction: column;
13+
gap: 20px;
14+
}
15+
16+
17+
.input{
18+
padding: 20px;
19+
background-color: transparent;
20+
border: 2px solid #bbb;
21+
border-radius: 5px;
22+
color: #bbb;
23+
font-size: 20px;
24+
font-weight: bold;
25+
}
26+
27+
.button{
28+
width: 300px;
29+
padding: 20px;
30+
font-size: 15px;
31+
cursor: pointer;
32+
background-color: #09a27c;
33+
border: none;
34+
border-radius: 5px;
35+
color:white;
36+
font-weight: 700;
37+
}

src/app/dashboard/page.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"use client"
22

3+
import { useSession } from 'next-auth/react'
34
import React, { useEffect, useState } from 'react'
45
import useSWR from 'swr'
56

67
const Dashboard = () => {
8+
const session = useSession();
9+
console.log(session);
710
const fetcher = (...args) => fetch(...args).then(res => res.json())
811
const { data, err, isLoading } = useSWR('https://jsonplaceholder.typicode.com/posts', fetcher)
912
console.log(fetcher)

src/app/layout.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import Navbar from '@/components/navbar/Navbar'
22
import './globals.css'
3-
import { Inter ,Poppins} from 'next/font/google'
3+
import {Poppins} from 'next/font/google'
44
import Footer from '@/components/footer/Footer'
55
import { ThemeProvider } from '../context/ThemeContext';
6+
import AuthProvider from '@/components/AuthProvider/AuthProvider';
67

78
const poppins = Poppins({ weight: ['100','200','300','400','500','600','700','800','900'],subsets:['latin']});
89

@@ -16,11 +17,13 @@ export default function RootLayout({ children }) {
1617
<html lang="en">
1718
<body className={poppins.className}>
1819
<ThemeProvider>
19-
<div className="container">
20-
<Navbar/>
21-
{children}
22-
<Footer/>
23-
</div>
20+
<AuthProvider>
21+
<div className="container">
22+
<Navbar/>
23+
{children}
24+
<Footer/>
25+
</div>
26+
</AuthProvider>
2427
</ThemeProvider>
2528
</body>
2629
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use client";
2+
import { SessionProvider } from "next-auth/react";
3+
4+
5+
const AuthProvider = ({children})=>{
6+
return (
7+
<SessionProvider>
8+
{children}
9+
</SessionProvider>
10+
)
11+
};
12+
13+
14+
export default AuthProvider;

0 commit comments

Comments
 (0)