From fa30ba992b8afe8570e1c85c9f1cd3cf230d3957 Mon Sep 17 00:00:00 2001 From: Rudra ranjan Mohanty Date: Sat, 8 Nov 2025 14:47:28 +0530 Subject: [PATCH] Added google provider and some UI-responsiveness changes --- Video 131/actions/useractions.js | 22 +++--- Video 131/app/api/auth/[...nextauth]/route.js | 74 ++++++++++--------- Video 131/app/dashboard/page.js | 21 ++++-- Video 131/app/login/page.js | 42 +++++------ Video 131/app/page.js | 60 ++++++++------- Video 131/components/Navbar.js | 74 +++++++++++-------- Video 131/db/connectDb.js | 58 +++++++++++---- Video 131/package-lock.json | 15 ++-- 8 files changed, 216 insertions(+), 150 deletions(-) diff --git a/Video 131/actions/useractions.js b/Video 131/actions/useractions.js index 93e5bc1c..ffbd2977 100644 --- a/Video 131/actions/useractions.js +++ b/Video 131/actions/useractions.js @@ -9,7 +9,7 @@ import User from "@/models/User" export const initiate = async (amount, to_username, paymentform) => { await connectDb() // fetch the secret of the user who is getting the payment - let user = await User.findOne({username: to_username}) + let user = await User.findOne({ username: to_username }) const secret = user.razorpaysecret var instance = new Razorpay({ key_id: user.razorpayid, key_secret: secret }) @@ -24,7 +24,7 @@ export const initiate = async (amount, to_username, paymentform) => { let x = await instance.orders.create(options) // create a payment object which shows a pending payment in the database - await Payment.create({ oid: x.id, amount: amount/100, to_user: to_username, name: paymentform.name, message: paymentform.message }) + await Payment.create({ oid: x.id, amount: amount / 100, to_user: to_username, name: paymentform.name, message: paymentform.message }) return x @@ -41,8 +41,8 @@ export const fetchuser = async (username) => { export const fetchpayments = async (username) => { await connectDb() // find all payments sorted by decreasing order of amount and flatten object ids - let p = await Payment.find({ to_user: username, done:true }).sort({ amount: -1 }).limit(10).lean() - return p + let p = await Payment.find({ to_user: username, done: true }).sort({ amount: -1 }).limit(10).lean() + return JSON.parse(JSON.stringify(p)) } export const updateProfile = async (data, oldusername) => { @@ -54,16 +54,16 @@ export const updateProfile = async (data, oldusername) => { let u = await User.findOne({ username: ndata.username }) if (u) { return { error: "Username already exists" } - } - await User.updateOne({email: ndata.email}, ndata) + } + await User.updateOne({ email: ndata.email }, ndata) // Now update all the usernames in the Payments table - await Payment.updateMany({to_user: oldusername}, {to_user: ndata.username}) - + await Payment.updateMany({ to_user: oldusername }, { to_user: ndata.username }) + } - else{ + else { + - - await User.updateOne({email: ndata.email}, ndata) + await User.updateOne({ email: ndata.email }, ndata) } diff --git a/Video 131/app/api/auth/[...nextauth]/route.js b/Video 131/app/api/auth/[...nextauth]/route.js index 5facc1e2..986d5a59 100644 --- a/Video 131/app/api/auth/[...nextauth]/route.js +++ b/Video 131/app/api/auth/[...nextauth]/route.js @@ -1,22 +1,26 @@ import NextAuth from 'next-auth' // import AppleProvider from 'next-auth/providers/apple' // import FacebookProvider from 'next-auth/providers/facebook' -// import GoogleProvider from 'next-auth/providers/google' +import GoogleProvider from 'next-auth/providers/google' // import EmailProvider from 'next-auth/providers/email' import GitHubProvider from "next-auth/providers/github"; import mongoose from "mongoose"; import connectDb from '@/db/connectDb'; import User from '@/models/User'; import Payment from '@/models/Payment'; - -export const authoptions = NextAuth({ - providers: [ - // OAuth authentication providers... - GitHubProvider({ - clientId: process.env.GITHUB_ID, - clientSecret: process.env.GITHUB_SECRET - }), + +export const authoptions = NextAuth({ + providers: [ + // OAuth authentication providers... + GitHubProvider({ + clientId: process.env.GITHUB_ID, + clientSecret: process.env.GITHUB_SECRET + }), + GoogleProvider({ + clientId: process.env.GOOGLE_ID, + clientSecret: process.env.GOOGLE_SECRET, + }), // AppleProvider({ // clientId: process.env.APPLE_ID, // clientSecret: process.env.APPLE_SECRET @@ -34,30 +38,32 @@ export const authoptions = NextAuth({ // server: process.env.MAIL_SERVER, // from: 'NextAuth.js ' // }), - ], - callbacks: { - async signIn({ user, account, profile, email, credentials }) { - if(account.provider == "github") { - await connectDb() - // Check if the user already exists in the database - const currentUser = await User.findOne({email: email}) - if(!currentUser){ - // Create a new user - const newUser = await User.create({ - email: user.email, - username: user.email.split("@")[0], - }) - } - return true - } - }, - - async session({ session, user, token }) { - const dbUser = await User.findOne({email: session.user.email}) + ], + callbacks: { + async signIn({ user, account, profile, email, credentials }) { + if (account.provider == "github" || account.provider === 'google') { + await connectDb() + // Check if the user already exists in the database + const currentUser = await User.findOne({ email: user.email }) + if (!currentUser) { + // Create a new user + const newUser = await User.create({ + email: user.email, + username: user.email.split("@")[0], + }) + } + return true + } + }, + + async session({ session, user, token }) { + const dbUser = await User.findOne({ email: session.user.email }) + if (dbUser) { session.user.name = dbUser.username - return session - }, - } - }) + } + return session + }, + } +}) - export { authoptions as GET, authoptions as POST} \ No newline at end of file +export { authoptions as GET, authoptions as POST } \ No newline at end of file diff --git a/Video 131/app/dashboard/page.js b/Video 131/app/dashboard/page.js index 6bb6eaf5..c49bd972 100644 --- a/Video 131/app/dashboard/page.js +++ b/Video 131/app/dashboard/page.js @@ -1,15 +1,24 @@ -import Dashboard from '@/components/Dashboard' +'use client' +import React, { useEffect } from 'react' +import { useSession, signIn, signOut } from "next-auth/react" +import { useRouter } from 'next/navigation' +import Dashboard from '@/components/Dashboard.js' const DashboardPage = () => { + const { data: session } = useSession() + const router = useRouter() + useEffect(() => { + if (!session) { + router.push('/login') + } + }, [session, router]) return ( - +
+ +
) } export default DashboardPage -export const metadata = { - title: "Dashboard - Get Me A Chai", - } - \ No newline at end of file diff --git a/Video 131/app/login/page.js b/Video 131/app/login/page.js index d3ccbe64..3ea81436 100644 --- a/Video 131/app/login/page.js +++ b/Video 131/app/login/page.js @@ -1,29 +1,26 @@ -"use client" -import React, {useEffect} from 'react' +'use client' +import React, { useEffect } from 'react' import { useSession, signIn, signOut } from "next-auth/react" import { useRouter } from 'next/navigation' const Login = () => { const { data: session } = useSession() const router = useRouter() - useEffect(() => { - document.title = "Login - Get Me A Chai" - console.log(session) if (session) { router.push('/dashboard') } - }, []) - + }, [session, router]) return ( -
-

Login to Get Started

- -
+ <> +
+

Login/SignUp to GetMeAChai to get your fans to support you

+
+
-
-
+ ) } export default Login - \ No newline at end of file + diff --git a/Video 131/app/page.js b/Video 131/app/page.js index 09f779fb..bf7588b9 100644 --- a/Video 131/app/page.js +++ b/Video 131/app/page.js @@ -7,8 +7,8 @@ export default function Home() {
Get Me a Chai

- A crowdfunding platform for creators to fund their projects. - + A crowdfunding platform for creators to fund their projects. +

@@ -17,11 +17,11 @@ export default function Home() {

- + - +
@@ -30,36 +30,42 @@ export default function Home() {
-

Your Fans can buy you a Chai

-
-
- -

Fans want to help

-

Your fans are available to support you

-
-
- -

Fans want to contribute

-

Your fans are willing to contribute financially

-
-
- -

Fans want to collaborate

-

Your fans are ready to collaborate with you

-
-
-
+

Your Fans can buy you a Chai

+
+
+ +

Fans want to help

+

Your fans are available to support you

+
+
+ +

Fans want to contribute

+

Your fans are willing to contribute financially

+
+
+ +

Fans want to collaborate

+

Your fans are ready to collaborate with you

+
+
+

Learn more about us

{/* Responsive youtube embed */} -
- +
+ +
-
-
); diff --git a/Video 131/components/Navbar.js b/Video 131/components/Navbar.js index bda40a52..24512aa1 100644 --- a/Video 131/components/Navbar.js +++ b/Video 131/components/Navbar.js @@ -1,4 +1,5 @@ -"use client" +/* eslint-disable @next/next/no-img-element */ +'use client' import React, { useState } from 'react' import { useSession, signIn, signOut } from "next-auth/react" import Link from 'next/link' @@ -6,53 +7,68 @@ import Link from 'next/link' const Navbar = () => { const { data: session } = useSession() const [showdropdown, setShowdropdown] = useState(false) - - + // if (session) { + // return ( + // <> + // Signed in as {session.user.email}
+ // + // + // ) + // } return ( -