From bf2cb861bcfd33fb4729a3f4c5bbe9c819bfdcfc Mon Sep 17 00:00:00 2001 From: prthpx Date: Sat, 11 Oct 2025 23:24:33 +0530 Subject: [PATCH] added GitHub OAuth provider and sign-in button --- apps/web/src/components/login/SignInPage.tsx | 8 +++++++- apps/web/src/lib/auth/config.ts | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/apps/web/src/components/login/SignInPage.tsx b/apps/web/src/components/login/SignInPage.tsx index 58bda7c..721861d 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,6 +32,12 @@ const SignInPage = () => { Continue with Google + signIn("github", { callbackUrl: "/dashboard/home" })} classname="w-full max-w-[380px] z-20 "> +
+ +
+ Continue with GitHub +
); }; diff --git a/apps/web/src/lib/auth/config.ts b/apps/web/src/lib/auth/config.ts index b8763ad..ac24356 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 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,21 @@ 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!, + authorization: { + params: { scope: "read:user user:email" }, + }, + }), ], callbacks: { - async signIn({ user, profile }) { + async signIn({ user, profile, account }) { try { await serverTrpc.auth.googleAuth.mutate({ email: user.email!, - firstName: profile?.name, - authMethod: "google", + firstName: user.name ?? (profile as any)?.name, + authMethod: account?.provider ?? "google", }); return true; @@ -39,7 +47,7 @@ export const authConfig: NextAuthOptions = { const data = await serverTrpc.auth.googleAuth.mutate({ email: user.email!, firstName: user.name ?? undefined, - authMethod: "google", + authMethod: account.provider ?? "google", }); token.jwtToken = data.token;