fix: return clear error when social auth provider is not configured

This commit is contained in:
Rotimi Best
2026-06-14 09:56:30 +01:00
parent 64571dd5ec
commit ee4d4922d6
13 changed files with 41 additions and 14 deletions
+16
View File
@@ -7,6 +7,7 @@ import { randomBytes } from 'crypto';
import { API_SERVER_URL } from '@api/constants'; import { API_SERVER_URL } from '@api/constants';
import { Hono } from '@api/utils/hono'; import { Hono } from '@api/utils/hono';
import { ErrorCodes } from '@api/utils/errors';
import { accountRouter } from '@api/routes/account'; import { accountRouter } from '@api/routes/account';
import { agentRouter } from '@api/routes/agent'; import { agentRouter } from '@api/routes/agent';
import { auth } from '@cio/db/auth'; 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); const response = await auth.handler(request);
// Outbound: if the OAuth callback redirected to // Outbound: if the OAuth callback redirected to
@@ -6,6 +6,7 @@
import { currentOrg } from '$lib/utils/store/org'; import { currentOrg } from '$lib/utils/store/org';
import { GoogleIconColored } from '$features/ui/icons'; import { GoogleIconColored } from '$features/ui/icons';
import { authClient } from '$lib/utils/services/auth/client'; import { authClient } from '$lib/utils/services/auth/client';
import { snackbar } from '$features/ui/snackbar/store';
import * as Card from '@cio/ui/base/card'; import * as Card from '@cio/ui/base/card';
import { Button } from '@cio/ui/base/button'; import { Button } from '@cio/ui/base/button';
import { Separator } from '@cio/ui/base/separator'; import { Separator } from '@cio/ui/base/separator';
@@ -51,17 +52,16 @@
const redirectTo = `${window.location.origin + pathname}`; const redirectTo = `${window.location.origin + pathname}`;
const errorCallbackURL = `${window.location.origin + ROUTE.AUTH_FAILED}`; const errorCallbackURL = `${window.location.origin + ROUTE.AUTH_FAILED}`;
console.log({ redirectTo });
try { try {
console.log('signInWithGoogle'); const result = await authClient.signIn.social({
const data = await authClient.signIn.social({
provider: 'google', provider: 'google',
callbackURL: redirectTo, callbackURL: redirectTo,
errorCallbackURL: errorCallbackURL errorCallbackURL: errorCallbackURL
}); });
console.log('data', data); if (result?.error) {
snackbar.error('snackbar.social_auth_not_enabled');
}
} catch (error) { } catch (error) {
console.log('catch error', error); console.log('catch error', error);
} }
@@ -435,7 +435,8 @@
"lesson_video": { "lesson_video": {
"generate_1080_completed": "1080p gengivelse tilføjet", "generate_1080_completed": "1080p gengivelse tilføjet",
"generate_1080_failed": "Kunne ikke generere 1080p gengivelse" "generate_1080_failed": "Kunne ikke generere 1080p gengivelse"
} },
"social_auth_not_enabled": "Denne godkendelsesudbyder er ikke aktiveret."
}, },
"explore": { "explore": {
"heading": "Udforsk vores kurser", "heading": "Udforsk vores kurser",
@@ -435,7 +435,8 @@
"lesson_video": { "lesson_video": {
"generate_1080_completed": "1080p-Wiedergabe hinzugefügt", "generate_1080_completed": "1080p-Wiedergabe hinzugefügt",
"generate_1080_failed": "Die 1080p-Wiedergabe konnte nicht generiert werden" "generate_1080_failed": "Die 1080p-Wiedergabe konnte nicht generiert werden"
} },
"social_auth_not_enabled": "Dieser Authentifizierungsanbieter ist nicht aktiviert."
}, },
"explore": { "explore": {
"heading": "Entdecken Sie unsere Kurse", "heading": "Entdecken Sie unsere Kurse",
@@ -3981,6 +3981,7 @@
"success_update": "Updated successfully", "success_update": "Updated successfully",
"success_delete": "Deleted successfully", "success_delete": "Deleted successfully",
"error_update": "Failed to update", "error_update": "Failed to update",
"social_auth_not_enabled": "This auth provider isn't enabled.",
"automation": { "automation": {
"created": "Automation key created. Save it now because the full secret is only shown once.", "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.", "rotated": "Automation key rotated. Save the new secret now because it will not be shown again.",
@@ -435,7 +435,8 @@
"lesson_video": { "lesson_video": {
"generate_1080_completed": "Se agregó una reproducción de 1080p", "generate_1080_completed": "Se agregó una reproducción de 1080p",
"generate_1080_failed": "No se pudo generar 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": { "explore": {
"heading": "Explora nuestros cursos", "heading": "Explora nuestros cursos",
@@ -435,7 +435,8 @@
"lesson_video": { "lesson_video": {
"generate_1080_completed": "Rendu 1080p ajouté", "generate_1080_completed": "Rendu 1080p ajouté",
"generate_1080_failed": "Impossible de générer un rendu 1080p" "generate_1080_failed": "Impossible de générer un rendu 1080p"
} },
"social_auth_not_enabled": "Ce fournisseur d'authentification n'est pas activé."
}, },
"explore": { "explore": {
"heading": "Découvrez nos cours", "heading": "Découvrez nos cours",
@@ -435,7 +435,8 @@
"lesson_video": { "lesson_video": {
"generate_1080_completed": "1080p प्रस्तुतिकरण जोड़ा गया", "generate_1080_completed": "1080p प्रस्तुतिकरण जोड़ा गया",
"generate_1080_failed": "1080p प्रस्तुतिकरण उत्पन्न नहीं हो सका" "generate_1080_failed": "1080p प्रस्तुतिकरण उत्पन्न नहीं हो सका"
} },
"social_auth_not_enabled": "यह प्रमाणीकरण प्रदाता सक्षम नहीं है."
}, },
"explore": { "explore": {
"heading": "हमारे पाठ्यक्रमों का अन्वेषण करें", "heading": "हमारे पाठ्यक्रमों का अन्वेषण करें",
@@ -435,7 +435,8 @@
"lesson_video": { "lesson_video": {
"generate_1080_completed": "Dodano wersję 1080p", "generate_1080_completed": "Dodano wersję 1080p",
"generate_1080_failed": "Nie można wygenerować wersji 1080p" "generate_1080_failed": "Nie można wygenerować wersji 1080p"
} },
"social_auth_not_enabled": "Ten dostawca uwierzytelniania nie jest włączony."
}, },
"explore": { "explore": {
"heading": "Poznaj nasze kursy", "heading": "Poznaj nasze kursy",
@@ -435,7 +435,8 @@
"lesson_video": { "lesson_video": {
"generate_1080_completed": "Versão 1080p adicionada", "generate_1080_completed": "Versão 1080p adicionada",
"generate_1080_failed": "Não foi possível gerar a renderização em 1080p" "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": { "explore": {
"heading": "Explore nossos cursos", "heading": "Explore nossos cursos",
@@ -435,7 +435,8 @@
"lesson_video": { "lesson_video": {
"generate_1080_completed": "добавлено воспроизведение 1080p", "generate_1080_completed": "добавлено воспроизведение 1080p",
"generate_1080_failed": "Не удалось создать воспроизведение 1080p." "generate_1080_failed": "Не удалось создать воспроизведение 1080p."
} },
"social_auth_not_enabled": "Этот поставщик аутентификации не включен."
}, },
"explore": { "explore": {
"heading": "Ознакомьтесь с нашими курсами", "heading": "Ознакомьтесь с нашими курсами",
@@ -435,7 +435,8 @@
"lesson_video": { "lesson_video": {
"generate_1080_completed": "Đã thêm phiên bản 1080p", "generate_1080_completed": "Đã thêm phiên bản 1080p",
"generate_1080_failed": "Không thể tạo 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": { "explore": {
"heading": "Khám phá các khóa học của chúng tôi", "heading": "Khám phá các khóa học của chúng tôi",
@@ -143,6 +143,7 @@ export const ErrorCodes = {
SSO_REGISTRATION_FAILED: 'SSO_REGISTRATION_FAILED', SSO_REGISTRATION_FAILED: 'SSO_REGISTRATION_FAILED',
SSO_NOT_FOUND: 'SSO_NOT_FOUND', SSO_NOT_FOUND: 'SSO_NOT_FOUND',
SSO_NOT_ENABLED: 'SSO_NOT_ENABLED', SSO_NOT_ENABLED: 'SSO_NOT_ENABLED',
SOCIAL_AUTH_NOT_ENABLED: 'SOCIAL_AUTH_NOT_ENABLED',
UPGRADE_REQUIRED: 'UPGRADE_REQUIRED', UPGRADE_REQUIRED: 'UPGRADE_REQUIRED',
CONFLICT: 'CONFLICT', CONFLICT: 'CONFLICT',