diff --git a/apps/web/app/(auth)/signin/_components/GitHubLogin.tsx b/apps/web/app/(auth)/signin/_components/GitHubLogin.tsx
new file mode 100644
index 00000000..6d35e89f
--- /dev/null
+++ b/apps/web/app/(auth)/signin/_components/GitHubLogin.tsx
@@ -0,0 +1,25 @@
+import { signIn } from "@/server/auth";
+import { Github } from "@repo/ui/components/icons";
+
+function GitHubLogin() {
+ return (
+
+ )
+}
+
+export default GitHubLogin;
\ No newline at end of file
diff --git a/apps/web/app/(auth)/signin/_components/GoogleLogin.tsx b/apps/web/app/(auth)/signin/_components/GoogleLogin.tsx
new file mode 100644
index 00000000..13b6986d
--- /dev/null
+++ b/apps/web/app/(auth)/signin/_components/GoogleLogin.tsx
@@ -0,0 +1,25 @@
+import { signIn } from "@/server/auth";
+import { Google } from "@repo/ui/components/icons";
+
+function GoogleLogin() {
+ return (
+
+ )
+}
+
+export default GoogleLogin;
\ No newline at end of file
diff --git a/apps/web/app/(auth)/signin/page.tsx b/apps/web/app/(auth)/signin/page.tsx
index 3b563b90..afdb0472 100644
--- a/apps/web/app/(auth)/signin/page.tsx
+++ b/apps/web/app/(auth)/signin/page.tsx
@@ -1,12 +1,12 @@
import Image from "next/image";
import Link from "next/link";
import Logo from "@/public/logo.svg";
-import { auth, signIn } from "@/server/auth";
-import { Google } from "@repo/ui/components/icons";
+import { auth } from "@/server/auth";
import gradientStyle from "./_components/TextGradient/gradient.module.css";
import { cn } from "@repo/ui/lib/utils";
import { redirect } from "next/navigation";
-import { toast } from "sonner";
+import GoogleLogin from "./_components/GoogleLogin";
+import GitHubLogin from "./_components/GitHubLogin";
export const runtime = "edge";
@@ -60,22 +60,12 @@ async function Signin({
-
+
+
+
+
diff --git a/apps/web/app/actions/fetchers.ts b/apps/web/app/actions/fetchers.ts
index 8d6802a7..108f5086 100644
--- a/apps/web/app/actions/fetchers.ts
+++ b/apps/web/app/actions/fetchers.ts
@@ -3,6 +3,7 @@
import { and, asc, eq, exists, not, or } from "drizzle-orm";
import { db } from "../../server/db";
import {
+ accounts,
canvas,
chatHistory,
ChatThread,
@@ -39,6 +40,18 @@ export const getUser = async (): ServerActionReturnType => {
return { success: true, data: user };
};
+export const getProvider = async (userId: string): ServerActionReturnType => {
+ const account = await db.query.accounts.findFirst({
+ where: eq(accounts.userId, userId),
+ });
+
+ if (!account) {
+ return { error: "No account found", success: false };
+ }
+
+ return { success: true, data: account.provider };
+}
+
export const getSpaces = async (): ServerActionReturnType => {
const data = await auth();
diff --git a/apps/web/app/api/ensureAuth.ts b/apps/web/app/api/ensureAuth.ts
index 1fcd2914..95d27a54 100644
--- a/apps/web/app/api/ensureAuth.ts
+++ b/apps/web/app/api/ensureAuth.ts
@@ -1,6 +1,6 @@
import { NextRequest } from "next/server";
import { db } from "../../server/db";
-import { accounts, sessions, users } from "../../server/db/schema";
+import { sessions, users } from "../../server/db/schema";
import { eq } from "drizzle-orm";
export async function ensureAuth(req: NextRequest) {
@@ -31,21 +31,25 @@ export async function ensureAuth(req: NextRequest) {
console.log(token, newToken);
- const authUserFetch = await fetch(
+ const tokenInfo = await fetch(
`https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=${newToken}`,
);
- if (!authUserFetch.ok) {
+ const userInfo = await fetch(
+ `https://www.googleapis.com/oauth2/v1/userinfo?access_token=${newToken}`,
+ );
+
+ if (!tokenInfo.ok) {
console.error(
"Error fetching Google user,",
- authUserFetch.statusText,
- await authUserFetch.text(),
+ tokenInfo.statusText,
+ await tokenInfo.text(),
);
console.log("Google user not found or error.");
return undefined;
}
- const authUserData = (await authUserFetch.json()) as {
+ const authUserData = (await tokenInfo.json()) as {
email: string;
audience: string;
issued_to: string;
diff --git a/apps/web/server/auth.ts b/apps/web/server/auth.ts
index 78671551..71a1ff8f 100644
--- a/apps/web/server/auth.ts
+++ b/apps/web/server/auth.ts
@@ -1,5 +1,6 @@
import NextAuth, { NextAuthResult } from "next-auth";
import Google from "next-auth/providers/google";
+import GitHub from "next-auth/providers/github";
import { DrizzleAdapter } from "@auth/drizzle-adapter";
import { db } from "./db";
import { accounts, sessions, users, verificationTokens } from "./db/schema";
@@ -31,5 +32,9 @@ export const {
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
+ GitHub({
+ clientId: process.env.GITHUB_CLIENT_ID,
+ clientSecret: process.env.GITHUB_CLIENT_SECRET,
+ }),
],
});