diff --git a/apps/api/src/app.ts b/apps/api/src/app.ts index 5737ebd7..76521596 100644 --- a/apps/api/src/app.ts +++ b/apps/api/src/app.ts @@ -7,6 +7,7 @@ import { randomBytes } from 'crypto'; import { API_SERVER_URL } from '@api/constants'; import { Hono } from '@api/utils/hono'; +import { ErrorCodes } from '@api/utils/errors'; import { accountRouter } from '@api/routes/account'; import { agentRouter } from '@api/routes/agent'; import { auth } from '@cio/db/auth'; @@ -141,6 +142,21 @@ export const app = new Hono() } } + // Check if the social auth provider is configured before forwarding + // to Better Auth, which returns a confusing generic 500 otherwise. + if (c.req.method === 'POST' && c.req.path === '/api/auth/sign-in/social') { + if (!process.env.GOOGLE_CLIENT_ID || !process.env.GOOGLE_CLIENT_SECRET) { + return c.json( + { + success: false, + error: "This auth provider isn't enabled.", + code: ErrorCodes.SOCIAL_AUTH_NOT_ENABLED + }, + 400 + ); + } + } + const response = await auth.handler(request); // Outbound: if the OAuth callback redirected to diff --git a/apps/dashboard/src/lib/features/ui/auth-ui.svelte b/apps/dashboard/src/lib/features/ui/auth-ui.svelte index 0866cea0..04a8d496 100644 --- a/apps/dashboard/src/lib/features/ui/auth-ui.svelte +++ b/apps/dashboard/src/lib/features/ui/auth-ui.svelte @@ -6,6 +6,7 @@ import { currentOrg } from '$lib/utils/store/org'; import { GoogleIconColored } from '$features/ui/icons'; import { authClient } from '$lib/utils/services/auth/client'; + import { snackbar } from '$features/ui/snackbar/store'; import * as Card from '@cio/ui/base/card'; import { Button } from '@cio/ui/base/button'; import { Separator } from '@cio/ui/base/separator'; @@ -51,17 +52,16 @@ const redirectTo = `${window.location.origin + pathname}`; const errorCallbackURL = `${window.location.origin + ROUTE.AUTH_FAILED}`; - console.log({ redirectTo }); - try { - console.log('signInWithGoogle'); - const data = await authClient.signIn.social({ + const result = await authClient.signIn.social({ provider: 'google', callbackURL: redirectTo, errorCallbackURL: errorCallbackURL }); - console.log('data', data); + if (result?.error) { + snackbar.error('snackbar.social_auth_not_enabled'); + } } catch (error) { console.log('catch error', error); } diff --git a/apps/dashboard/src/lib/utils/translations/da.json b/apps/dashboard/src/lib/utils/translations/da.json index f751ea3f..41011b0d 100644 --- a/apps/dashboard/src/lib/utils/translations/da.json +++ b/apps/dashboard/src/lib/utils/translations/da.json @@ -435,7 +435,8 @@ "lesson_video": { "generate_1080_completed": "1080p gengivelse tilføjet", "generate_1080_failed": "Kunne ikke generere 1080p gengivelse" - } + }, + "social_auth_not_enabled": "Denne godkendelsesudbyder er ikke aktiveret." }, "explore": { "heading": "Udforsk vores kurser", diff --git a/apps/dashboard/src/lib/utils/translations/de.json b/apps/dashboard/src/lib/utils/translations/de.json index 317a0c81..1bc638f5 100644 --- a/apps/dashboard/src/lib/utils/translations/de.json +++ b/apps/dashboard/src/lib/utils/translations/de.json @@ -435,7 +435,8 @@ "lesson_video": { "generate_1080_completed": "1080p-Wiedergabe hinzugefügt", "generate_1080_failed": "Die 1080p-Wiedergabe konnte nicht generiert werden" - } + }, + "social_auth_not_enabled": "Dieser Authentifizierungsanbieter ist nicht aktiviert." }, "explore": { "heading": "Entdecken Sie unsere Kurse", diff --git a/apps/dashboard/src/lib/utils/translations/en.json b/apps/dashboard/src/lib/utils/translations/en.json index f1d5310c..ad2f44c8 100644 --- a/apps/dashboard/src/lib/utils/translations/en.json +++ b/apps/dashboard/src/lib/utils/translations/en.json @@ -3981,6 +3981,7 @@ "success_update": "Updated successfully", "success_delete": "Deleted successfully", "error_update": "Failed to update", + "social_auth_not_enabled": "This auth provider isn't enabled.", "automation": { "created": "Automation key created. Save it now because the full secret is only shown once.", "rotated": "Automation key rotated. Save the new secret now because it will not be shown again.", diff --git a/apps/dashboard/src/lib/utils/translations/es.json b/apps/dashboard/src/lib/utils/translations/es.json index 400a0c46..68e8d56a 100644 --- a/apps/dashboard/src/lib/utils/translations/es.json +++ b/apps/dashboard/src/lib/utils/translations/es.json @@ -435,7 +435,8 @@ "lesson_video": { "generate_1080_completed": "Se agregó una reproducción de 1080p", "generate_1080_failed": "No se pudo generar una reproducción de 1080p" - } + }, + "social_auth_not_enabled": "Este proveedor de autenticación no está habilitado." }, "explore": { "heading": "Explora nuestros cursos", diff --git a/apps/dashboard/src/lib/utils/translations/fr.json b/apps/dashboard/src/lib/utils/translations/fr.json index 5780c8e9..588263f9 100644 --- a/apps/dashboard/src/lib/utils/translations/fr.json +++ b/apps/dashboard/src/lib/utils/translations/fr.json @@ -435,7 +435,8 @@ "lesson_video": { "generate_1080_completed": "Rendu 1080p ajouté", "generate_1080_failed": "Impossible de générer un rendu 1080p" - } + }, + "social_auth_not_enabled": "Ce fournisseur d'authentification n'est pas activé." }, "explore": { "heading": "Découvrez nos cours", diff --git a/apps/dashboard/src/lib/utils/translations/hi.json b/apps/dashboard/src/lib/utils/translations/hi.json index dc9799b0..370c1b04 100644 --- a/apps/dashboard/src/lib/utils/translations/hi.json +++ b/apps/dashboard/src/lib/utils/translations/hi.json @@ -435,7 +435,8 @@ "lesson_video": { "generate_1080_completed": "1080p प्रस्तुतिकरण जोड़ा गया", "generate_1080_failed": "1080p प्रस्तुतिकरण उत्पन्न नहीं हो सका" - } + }, + "social_auth_not_enabled": "यह प्रमाणीकरण प्रदाता सक्षम नहीं है." }, "explore": { "heading": "हमारे पाठ्यक्रमों का अन्वेषण करें", diff --git a/apps/dashboard/src/lib/utils/translations/pl.json b/apps/dashboard/src/lib/utils/translations/pl.json index 968245d3..6cc3c2b6 100644 --- a/apps/dashboard/src/lib/utils/translations/pl.json +++ b/apps/dashboard/src/lib/utils/translations/pl.json @@ -435,7 +435,8 @@ "lesson_video": { "generate_1080_completed": "Dodano wersję 1080p", "generate_1080_failed": "Nie można wygenerować wersji 1080p" - } + }, + "social_auth_not_enabled": "Ten dostawca uwierzytelniania nie jest włączony." }, "explore": { "heading": "Poznaj nasze kursy", diff --git a/apps/dashboard/src/lib/utils/translations/pt.json b/apps/dashboard/src/lib/utils/translations/pt.json index 9d008177..6042fea9 100644 --- a/apps/dashboard/src/lib/utils/translations/pt.json +++ b/apps/dashboard/src/lib/utils/translations/pt.json @@ -435,7 +435,8 @@ "lesson_video": { "generate_1080_completed": "Versão 1080p adicionada", "generate_1080_failed": "Não foi possível gerar a renderização em 1080p" - } + }, + "social_auth_not_enabled": "Este provedor de autenticação não está habilitado." }, "explore": { "heading": "Explore nossos cursos", diff --git a/apps/dashboard/src/lib/utils/translations/ru.json b/apps/dashboard/src/lib/utils/translations/ru.json index 32e3d701..5dd7250b 100644 --- a/apps/dashboard/src/lib/utils/translations/ru.json +++ b/apps/dashboard/src/lib/utils/translations/ru.json @@ -435,7 +435,8 @@ "lesson_video": { "generate_1080_completed": "добавлено воспроизведение 1080p", "generate_1080_failed": "Не удалось создать воспроизведение 1080p." - } + }, + "social_auth_not_enabled": "Этот поставщик аутентификации не включен." }, "explore": { "heading": "Ознакомьтесь с нашими курсами", diff --git a/apps/dashboard/src/lib/utils/translations/vi.json b/apps/dashboard/src/lib/utils/translations/vi.json index 482e47fa..59ca1eca 100644 --- a/apps/dashboard/src/lib/utils/translations/vi.json +++ b/apps/dashboard/src/lib/utils/translations/vi.json @@ -435,7 +435,8 @@ "lesson_video": { "generate_1080_completed": "Đã thêm phiên bản 1080p", "generate_1080_failed": "Không thể tạo phiên bản 1080p" - } + }, + "social_auth_not_enabled": "Nhà cung cấp xác thực này chưa được kích hoạt." }, "explore": { "heading": "Khám phá các khóa học của chúng tôi", diff --git a/packages/utils/src/constants/error-codes.ts b/packages/utils/src/constants/error-codes.ts index 2c43d22c..8eaa4842 100644 --- a/packages/utils/src/constants/error-codes.ts +++ b/packages/utils/src/constants/error-codes.ts @@ -143,6 +143,7 @@ export const ErrorCodes = { SSO_REGISTRATION_FAILED: 'SSO_REGISTRATION_FAILED', SSO_NOT_FOUND: 'SSO_NOT_FOUND', SSO_NOT_ENABLED: 'SSO_NOT_ENABLED', + SOCIAL_AUTH_NOT_ENABLED: 'SOCIAL_AUTH_NOT_ENABLED', UPGRADE_REQUIRED: 'UPGRADE_REQUIRED', CONFLICT: 'CONFLICT',