import { d as defineEventHandler, c as createError, aQ as useRuntimeConfig, aP as sendRedirect } from '../../../nitro/nitro.mjs';
import { i as isValidProvider, a as generateAuthUrl } from '../../../_/oauth.mjs';
import 'node:crypto';
import 'jsonwebtoken';
import 'node:fs';
import 'node:module';
import 'node:path';
import 'node:url';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'pino';
import 'drizzle-orm/better-sqlite3';
import 'drizzle-orm/node-postgres';
import 'drizzle-orm/mysql2';
import 'better-sqlite3';
import 'pg';
import 'mysql2/promise';
import 'drizzle-orm';
import 'fs';
import 'path';
import 'prom-client';
import 'bcryptjs';
import '@node-rs/argon2';
import 'node:async_hooks';
import 'crypto';
import 'node:dns';
import 'node:util';
import 'node:net';
import 'fs/promises';
import 'url';
import 'semver';

const index_get = defineEventHandler((event) => {
  var _a, _b;
  try {
    const provider = (_a = event.context.params) == null ? void 0 : _a.provider;
    if (!provider || !isValidProvider(provider)) {
      throw createError({
        statusCode: 400,
        statusMessage: "Bad Request",
        message: "Invalid OAuth provider. Supported: google, github, facebook, vk"
      });
    }
    const config = useRuntimeConfig();
    const apiBase = config.public.apiBase || "http://localhost:2102";
    const callbackUrl = `${apiBase}/api/auth/${provider}/callback`;
    const authUrl = generateAuthUrl(provider, callbackUrl);
    return sendRedirect(event, authUrl, 302);
  } catch (error) {
    if (error instanceof Error && error.message.includes("not configured")) {
      throw createError({
        statusCode: 503,
        statusMessage: "Service Unavailable",
        message: error.message
      });
    }
    console.error(`[GET /api/auth/${(_b = event.context.params) == null ? void 0 : _b.provider}] Error:`, error);
    throw createError({
      statusCode: 500,
      statusMessage: "OAuth Redirect Failed",
      message: error instanceof Error ? error.message : "Unknown error"
    });
  }
});

export { index_get as default };
//# sourceMappingURL=index.get.mjs.map
