diff --git a/src/app/page.tsx b/src/app/page.tsx index cb51474..2051de0 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -10,7 +10,7 @@ export default async function HomePage() { redirect("/dashboard"); } - return ( + return (

DevTrack

@@ -18,18 +18,20 @@ export default async function HomePage() { Open-source developer productivity dashboard. Track coding habits, visualize GitHub contributions, and hit your goals.

-
+ +
- Sign in with GitHub + Sign In + View on GitHub @@ -37,4 +39,5 @@ export default async function HomePage() {
); -} + +} \ No newline at end of file diff --git a/src/app/signin/page.tsx b/src/app/signin/page.tsx new file mode 100644 index 0000000..207d871 --- /dev/null +++ b/src/app/signin/page.tsx @@ -0,0 +1,73 @@ +"use client"; + +import { signIn } from "next-auth/react"; +import { useEffect } from "react"; +import { useSession } from "next-auth/react"; +import { useRouter } from "next/navigation"; + +export default function SignInPage() { + const { data: session, status } = useSession(); + const router = useRouter(); + + useEffect(() => { + if (status === "authenticated") { + router.push("/dashboard"); + } + }, [status, router]); + + const handleGitHubSignIn = async () => { + await signIn("github", { callbackUrl: "/dashboard" }); + }; + + const handleGoogleSignIn = async () => { + await signIn("google", { callbackUrl: "/dashboard" }); + }; + + if (status === "loading") { + return ( +
+
Loading...
+
+ ); + } + + return ( +
+
+
+

Welcome to DevTrack

+

Sign in to track your developer productivity

+ +
+ + + +
+ +

+ By signing in, you agree to our terms +

+
+
+
+ ); +} diff --git a/src/lib/auth.ts b/src/lib/auth.ts index fb3f421..e11ed64 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -1,5 +1,6 @@ import { type NextAuthOptions } from "next-auth"; import GitHubProvider from "next-auth/providers/github"; +import GoogleProvider from "next-auth/providers/google"; // ← New Import import { supabaseAdmin } from "./supabase"; const SESSION_MAX_AGE = 30 * 24 * 60 * 60; @@ -15,7 +16,20 @@ export const authOptions: NextAuthOptions = { params: { scope: "read:user user:email repo" }, }, }), + + GoogleProvider({ + clientId: process.env.GOOGLE_CLIENT_ID ?? "", + clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? "", + authorization: { + params: { + prompt: "consent", + access_type: "offline", + response_type: "code", + }, + }, + }), ], + session: { strategy: "jwt", maxAge: SESSION_MAX_AGE, @@ -56,9 +70,11 @@ export const authOptions: NextAuthOptions = { async jwt({ token, account, profile }) { if (account?.access_token) token.accessToken = account.access_token; if (profile) { - const p = profile as { id: number; login: string }; - token.githubId = String(p.id); - token.githubLogin = p.login; + if (account?.provider === "github") { + const p = profile as { id: number; login: string }; + token.githubId = String(p.id); + token.githubLogin = p.login; + } } return token; }, @@ -73,4 +89,4 @@ export const authOptions: NextAuthOptions = { }, }, secret: process.env.NEXTAUTH_SECRET, -}; +}; \ No newline at end of file