Skip to content
Closed
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
9 changes: 8 additions & 1 deletion apps/web/src/components/login/SignInPage.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -32,9 +32,16 @@ const SignInPage = () => {
</div>
Continue with Google
</PrimaryButton>
<PrimaryButton onClick={() => signIn("github", { callbackUrl: "/dashboard/home" })} classname="w-full max-w-[380px] z-20 ">
<div className="w-6">
<Github />
</div>
Continue with GitHub
</PrimaryButton>
</div>
);
};

export default SignInPage;


35 changes: 27 additions & 8 deletions apps/web/src/lib/auth/config.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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;
Expand All @@ -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;
Expand Down