diff --git a/apps/web/src/components/login/SignInPage.tsx b/apps/web/src/components/login/SignInPage.tsx index 58bda7c..b22202b 100644 --- a/apps/web/src/components/login/SignInPage.tsx +++ b/apps/web/src/components/login/SignInPage.tsx @@ -1,7 +1,7 @@ "use client"; import { signIn } from "next-auth/react"; import PrimaryButton from "../ui/custom-button"; -import { Google } from "../icons/icons"; +import { Google, Github } from "../icons/icons"; import Image from "next/image"; import Overlay from "../ui/overlay"; @@ -32,9 +32,16 @@ const SignInPage = () => { Continue with Google + signIn("github", { callbackUrl: "/dashboard/home" })} classname="w-full max-w-[380px] z-20 "> +
+ +
+ Continue with GitHub +
); }; export default SignInPage; + diff --git a/apps/web/src/lib/auth/config.ts b/apps/web/src/lib/auth/config.ts index b8763ad..647cd74 100644 --- a/apps/web/src/lib/auth/config.ts +++ b/apps/web/src/lib/auth/config.ts @@ -1,5 +1,6 @@ -import type { NextAuthOptions } from "next-auth"; +import NextAuth, { type NextAuthOptions } from "next-auth"; import GoogleProvider from "next-auth/providers/google"; +import GitHubProvider from "next-auth/providers/github"; import { serverTrpc } from "../trpc-server"; export const authConfig: NextAuthOptions = { @@ -8,14 +9,25 @@ export const authConfig: NextAuthOptions = { clientId: process.env.GOOGLE_CLIENT_ID!, clientSecret: process.env.GOOGLE_CLIENT_SECRET!, }), + GitHubProvider({ + clientId: process.env.GITHUB_CLIENT_ID!, + clientSecret: process.env.GITHUB_CLIENT_SECRET!, + }), ], callbacks: { - async signIn({ user, profile }) { + async signIn({ user, profile, account }) { try { + if (!user.email) { + console.error("Sign-in error: Email is required"); + return false; + } + + const authMethod = account?.provider === "github" ? "github" : "google"; + await serverTrpc.auth.googleAuth.mutate({ - email: user.email!, - firstName: profile?.name, - authMethod: "google", + email: user.email, + firstName: profile?.name || user.name || undefined, + authMethod: authMethod, }); return true; @@ -36,10 +48,17 @@ export const authConfig: NextAuthOptions = { async jwt({ token, account, user }) { if (account && user) { try { + if (!user.email) { + console.error("JWT token error: Email is required"); + return token; + } + + const authMethod = account.provider === "github" ? "github" : "google"; + const data = await serverTrpc.auth.googleAuth.mutate({ - email: user.email!, - firstName: user.name ?? undefined, - authMethod: "google", + email: user.email, + firstName: user.name || undefined, + authMethod: authMethod, }); token.jwtToken = data.token;