Skip to content

Commit

Permalink
feat/nextAuth-setting
Browse files Browse the repository at this point in the history
  • Loading branch information
nowrobin committed Jul 1, 2024
1 parent ab0a1b3 commit fe06049
Show file tree
Hide file tree
Showing 9 changed files with 598 additions and 1,301 deletions.
9 changes: 9 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ POSTGRES_DATABASE="verceldb"



GOOGLE_CLIENT_ID="856852514692-3bntvuduhn28in4lss3dr1cu358hfmbi.apps.googleusercontent.com"
GOOGLE_CLIENT_SECRET="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"

GOOGLE_CLIENT_ID_DEV="856852514692-cc7ouompuehfk55dsknjal9312f3kp33.apps.googleusercontent.com"
GOOGLE_CLIENT_SECRET_DEV="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"


NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="thisisexampleofsecret"
1,790 changes: 491 additions & 1,299 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@prisma/client": "^5.14.0",
"@vercel/postgres": "^0.8.0",
"next": "14.2.3",
"next-auth": "^4.24.7",
"react": "^18",
"react-dom": "^18"
},
Expand All @@ -23,9 +24,9 @@
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.3",
"prisma": "^5.14.0",
"jest": "^29.7.0",
"postcss": "^8",
"prisma": "^5.14.0",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
Expand Down
37 changes: 37 additions & 0 deletions src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";

const handler = NextAuth({
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID_DEV as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET_DEV as string,
}),
],
callbacks: {
// async signIn({ user, account, profile, email, credentials }) {
// const isAllowedToSignIn = true;
// if (isAllowedToSignIn) {
// return "/";
// } else {
// // Return false to display a default error message
// return "/";
// // Or you can return a URL to redirect to:
// // return '/unauthorized'
// }
// },
// async redirect({ url, baseUrl }) {
// return baseUrl;
// },
// async session({ session, user, token }) {
// return session;
// },
// async jwt({ token, user, account }) {
// if (account) {
// token.accessToken = account.access_token;
// }
// return token;
// },
},
});
export { handler as GET, handler as POST };
11 changes: 11 additions & 0 deletions src/app/api/auth/providers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use client";

import { SessionProvider } from "next-auth/react";

type Props = {
children: React.ReactNode;
};

export default function AuthContext({ children }: Props) {
return <SessionProvider>{children}</SessionProvider>;
}
22 changes: 22 additions & 0 deletions src/app/component/header/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use client";

import { useSession } from "next-auth/react";
import Link from "next/link";

export default function Header() {
const { data: session, status } = useSession();
console.log(session);
return (
<div className="absolute flex flex-row gap-10 right-[32rem]">
<div>Main</div>
{session ? (
<div></div>
) : (
<div>
<Link href={"/login"}>Login</Link>
{/* <Link></Link> */}
</div>
)}
</div>
);
}
10 changes: 9 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import Header from "./component/header/page";

import AuthContext from "./api/auth/providers";

const inter = Inter({ subsets: ["latin"] });

Expand All @@ -16,7 +19,12 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<body className={inter.className}>
<AuthContext>
<Header></Header>
{children}
</AuthContext>
</body>
</html>
);
}
15 changes: 15 additions & 0 deletions src/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use client";

import { signIn, useSession } from "next-auth/react";
import Link from "next/link";

export default function Login() {
const { data: session } = useSession();
return session ? (
<div>
Already Logged In go back to <Link href={"/"}>Main Page</Link>
</div>
) : (
<button onClick={() => signIn("google")}>Google LogIn</button>
);
}
2 changes: 2 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import { useSession } from "next-auth/react";
import { useEffect, useState } from "react";

interface Word {
Expand All @@ -13,6 +14,7 @@ interface Letter extends Word {
}

export default function Home() {
//Get Session Info
//For sentence
const [sentenceCurrent, setSentenceCurrent] = useState(0); //sentence Current position
const [textValue, setTextValue] = useState(""); //for the print text
Expand Down

0 comments on commit fe06049

Please sign in to comment.