Initial commit

This commit is contained in:
Developer
2026-02-06 21:44:04 -06:00
commit f85e93c7a6
151 changed files with 22916 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import { getAuth } from "@/lib/auth";
import { NextRequest, NextResponse } from "next/server";
export const runtime = "nodejs";
export async function GET(req: NextRequest) {
try {
const auth = await getAuth();
const response = await auth.handler(req);
const redirectUrl = req.nextUrl.searchParams.get("redirect") || "/account/webinars";
if (response.status >= 300 && response.status < 400) {
const location = response.headers.get("location");
if (location) {
return NextResponse.redirect(new URL(`/auth-callback?redirect=${encodeURIComponent(redirectUrl)}`, req.url));
}
}
return response;
} catch (error) {
console.error("Discord callback error:", error);
return new Response("Authentication failed", { status: 500 });
}
}

View File

@@ -0,0 +1,25 @@
import { getAuth } from "@/lib/auth";
import { NextRequest, NextResponse } from "next/server";
export const runtime = "nodejs";
export async function GET(req: NextRequest) {
try {
const auth = await getAuth();
const response = await auth.handler(req);
const redirectUrl = req.nextUrl.searchParams.get("redirect") || "/account/webinars";
if (response.status >= 300 && response.status < 400) {
const location = response.headers.get("location");
if (location) {
return NextResponse.redirect(new URL(`/auth-callback?redirect=${encodeURIComponent(redirectUrl)}`, req.url));
}
}
return response;
} catch (error) {
console.error("Facebook callback error:", error);
return new Response("Authentication failed", { status: 500 });
}
}

View File

@@ -0,0 +1,25 @@
import { getAuth } from "@/lib/auth";
import { NextRequest, NextResponse } from "next/server";
export const runtime = "nodejs";
export async function GET(req: NextRequest) {
try {
const auth = await getAuth();
const response = await auth.handler(req);
const redirectUrl = req.nextUrl.searchParams.get("redirect") || "/account/webinars";
if (response.status >= 300 && response.status < 400) {
const location = response.headers.get("location");
if (location) {
return NextResponse.redirect(new URL(`/auth-callback?redirect=${encodeURIComponent(redirectUrl)}`, req.url));
}
}
return response;
} catch (error) {
console.error("GitHub callback error:", error);
return new Response("Authentication failed", { status: 500 });
}
}

View File

@@ -0,0 +1,30 @@
import { getAuth } from "@/lib/auth";
import { NextRequest, NextResponse } from "next/server";
export const runtime = "nodejs";
export async function GET(req: NextRequest) {
try {
const auth = await getAuth();
const response = await auth.handler(req);
// Get redirect URL from query params if provided
const redirectUrl = req.nextUrl.searchParams.get("redirect") || "/account/webinars";
// If response is a redirect, extract location and modify it
if (response.status >= 300 && response.status < 400) {
const location = response.headers.get("location");
if (location) {
// If it's redirecting to a callback page, preserve the redirect param
return NextResponse.redirect(new URL(`/auth-callback?redirect=${encodeURIComponent(redirectUrl)}`, req.url));
}
}
// Otherwise return auth response as is, then frontend will handle redirect
return response;
} catch (error) {
console.error("Google callback error:", error);
return new Response("Authentication failed", { status: 500 });
}
}

51
app/auth/google/route.ts Normal file
View File

@@ -0,0 +1,51 @@
import { NextResponse } from "next/server";
import { loadSystemConfig } from "@/lib/system-config";
import crypto from "crypto";
import { cookies } from "next/headers";
export async function GET(request: Request) {
try {
const systemConfig = await loadSystemConfig();
const { googleAuth } = systemConfig;
if (!googleAuth?.clientId || !googleAuth?.clientSecret) {
return NextResponse.json(
{ ok: false, message: "Google OAuth not configured" },
{ status: 400 }
);
}
// Generate CSRF token
const state = crypto.randomBytes(32).toString("hex");
// Store state in cookie for verification
const cookieStore = await cookies();
cookieStore.set("oauth_state", state, {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
sameSite: "lax",
maxAge: 600, // 10 minutes
});
// Build Google OAuth URL
const params = new URLSearchParams({
client_id: googleAuth.clientId,
redirect_uri: `${process.env.APP_BASE_URL || "http://localhost:3001"}/auth/google/callback`,
response_type: "code",
scope: "openid email profile",
state,
access_type: "offline",
prompt: "consent",
});
const authUrl = `https://accounts.google.com/o/oauth2/v2/auth?${params.toString()}`;
return NextResponse.redirect(authUrl);
} catch (error) {
console.error("Google OAuth error:", error);
return NextResponse.json(
{ ok: false, message: "Failed to initiate OAuth" },
{ status: 500 }
);
}
}