Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arvind-[login] PR #14

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
CLIENT_ID='1059907364986-bnk71fjcv7tq9bo65mmklser56ghgdkb.apps.googleusercontent.com'
CLIENT_SECRET='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'
DATABASE_URL='e'
49 changes: 49 additions & 0 deletions app/auth/signin.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { useSession } from "next-auth/react";
import { signIn } from "next-auth/react";
import { useState } from "react";

const SignIn = (props) => {
const [userInfo, setUserInfo] = useState({ email: "", password: "" });
const { data: session, status } = useSession()
if (status === "authenticated") {
return <p>Signed in as {session.user.email}</p>
}
const handleSubmit = async (e) => {
// validate your userinfo
e.preventDefault();

const res = await signIn("credentials", {
email: userInfo.email,
password: userInfo.password, consolelog(session,status);
redirect: false,
});
console.log(session,status);
console.log(res);
};
return (
<div className="sign-in-form">
<form onSubmit={handleSubmit}>
<h1>Login</h1>
<input
value={userInfo.email}
onChange={({ target }) =>
setUserInfo({ ...userInfo, email: target.value })
}
type="email"
placeholder="[email protected]"
/>
<input
value={userInfo.password}
onChange={({ target }) =>
setUserInfo({ ...userInfo, password: target.value })
}
type="password"
placeholder="********"
/>
<input type="submit" value="Login" />
</form>
</div>
);
};

export default SignIn;
17 changes: 14 additions & 3 deletions components/SideNavbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ function MobileNav({ open, setOpen }) {
<Link className="text-xl font-medium my-4 text-white" href="/login" onClick={() => setTimeout(() => { setOpen(!open) }, 100)}>
Login
</Link>
<Link className="text-xl font-medium my-4 text-white" href="/generate" onClick={() => setTimeout(() => { setOpen(!open) }, 100)}>
signin
</Link>

<Link className="text-xl font-medium my-4 text-white" href="/generate" onClick={() => setTimeout(() => { setOpen(!open) }, 100)}>
Generate
</Link>
Expand Down Expand Up @@ -61,15 +65,22 @@ export default function Navbar() {
<NavLink to="/events">
Events
</NavLink>
<NavLink to="/login">
Login
</NavLink>

<NavLink to="/generate">
Generate
</NavLink>
<NavLink to="/scan">
Scan
</NavLink>
<NavLink to="/login">
Login
</NavLink>
<NavLink to="/signin">

Signin
</NavLink>


</div>
</div>
<div className='hidden md:flex right-0 font-serif font-semibold text-white mt-12 mr-2'>Hi Lead!</div>
Expand Down
1 change: 1 addition & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"jsx": "react",
"paths": {
"@/*": ["./*"]
}
Expand Down
136 changes: 136 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"autoprefixer": "10.4.14",
"framer-motion": "^10.12.12",
"next": "13.4.1",
"next-auth": "^4.22.1",
"postcss": "8.4.23",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
65 changes: 65 additions & 0 deletions pages/api/auth/[...nextauthmod].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import bcrypt from "bcrypt"
import NextAuth, { AuthOptions } from "next-auth"
import CredentialsProvider from "next-auth/providers/credentials"
import GithubProvider from "next-auth/providers/github"
import GoogleProvider from "next-auth/providers/google"
import { PrismaAdapter } from "@next-auth/prisma-adapter"

import prisma from "@/app/libs/prismadb"

export const authOptions = {
adapter: PrismaAdapter(prisma),
providers: [
GithubProvider({
clientId: process.env.GITHUB_ID ,
clientSecret: process.env.GITHUB_SECRET
}),
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID ,
clientSecret: process.env.GOOGLE_CLIENT_SECRET
}),
CredentialsProvider({
name: 'credentials',
credentials: {
email: { label: 'email', type: 'text' },
password: { label: 'password', type: 'password' }
},
async authorize(credentials) {
if (!credentials?.email || !credentials?.password) {
throw new Error('Invalid credentials');
}

const user = await prisma.user.findUnique({
where: {
email: credentials.email
}
});

if (!user || !user?.hashedPassword) {
throw new Error('Invalid credentials');
}

const isCorrectPassword = await bcrypt.compare(
credentials.password,
user.hashedPassword
);

if (!isCorrectPassword) {
throw new Error('Invalid credentials');
}

return user;
}
})
],
pages: {
signIn: '/',
},
debug: process.env.NODE_ENV === 'development',
session: {
strategy: "jwt",
},
secret: process.env.NEXTAUTH_SECRET,
}

export default NextAuth(authOptions);