Skip to content

Commit bf2cb86

Browse files
committed
added GitHub OAuth provider and sign-in button
1 parent 32c0ea4 commit bf2cb86

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

apps/web/src/components/login/SignInPage.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22
import { signIn } from "next-auth/react";
33
import PrimaryButton from "../ui/custom-button";
4-
import { Google } from "../icons/icons";
4+
import { Google, Github } from "../icons/icons";
55
import Image from "next/image";
66
import Overlay from "../ui/overlay";
77

@@ -32,6 +32,12 @@ const SignInPage = () => {
3232
</div>
3333
Continue with Google
3434
</PrimaryButton>
35+
<PrimaryButton onClick={() => signIn("github", { callbackUrl: "/dashboard/home" })} classname="w-full max-w-[380px] z-20 ">
36+
<div className="w-6">
37+
<Github />
38+
</div>
39+
Continue with GitHub
40+
</PrimaryButton>
3541
</div>
3642
);
3743
};

apps/web/src/lib/auth/config.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { NextAuthOptions } from "next-auth";
22
import GoogleProvider from "next-auth/providers/google";
3+
import GithubProvider from "next-auth/providers/github";
34
import { serverTrpc } from "../trpc-server";
45

56
export const authConfig: NextAuthOptions = {
@@ -8,14 +9,21 @@ export const authConfig: NextAuthOptions = {
89
clientId: process.env.GOOGLE_CLIENT_ID!,
910
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
1011
}),
12+
GithubProvider({
13+
clientId: process.env.GITHUB_CLIENT_ID!,
14+
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
15+
authorization: {
16+
params: { scope: "read:user user:email" },
17+
},
18+
}),
1119
],
1220
callbacks: {
13-
async signIn({ user, profile }) {
21+
async signIn({ user, profile, account }) {
1422
try {
1523
await serverTrpc.auth.googleAuth.mutate({
1624
email: user.email!,
17-
firstName: profile?.name,
18-
authMethod: "google",
25+
firstName: user.name ?? (profile as any)?.name,
26+
authMethod: account?.provider ?? "google",
1927
});
2028

2129
return true;
@@ -39,7 +47,7 @@ export const authConfig: NextAuthOptions = {
3947
const data = await serverTrpc.auth.googleAuth.mutate({
4048
email: user.email!,
4149
firstName: user.name ?? undefined,
42-
authMethod: "google",
50+
authMethod: account.provider ?? "google",
4351
});
4452

4553
token.jwtToken = data.token;

0 commit comments

Comments
 (0)