fix: return clear error when social auth provider is not configured
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -435,7 +435,8 @@
|
||||
"lesson_video": {
|
||||
"generate_1080_completed": "1080p प्रस्तुतिकरण जोड़ा गया",
|
||||
"generate_1080_failed": "1080p प्रस्तुतिकरण उत्पन्न नहीं हो सका"
|
||||
}
|
||||
},
|
||||
"social_auth_not_enabled": "यह प्रमाणीकरण प्रदाता सक्षम नहीं है."
|
||||
},
|
||||
"explore": {
|
||||
"heading": "हमारे पाठ्यक्रमों का अन्वेषण करें",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -435,7 +435,8 @@
|
||||
"lesson_video": {
|
||||
"generate_1080_completed": "добавлено воспроизведение 1080p",
|
||||
"generate_1080_failed": "Не удалось создать воспроизведение 1080p."
|
||||
}
|
||||
},
|
||||
"social_auth_not_enabled": "Этот поставщик аутентификации не включен."
|
||||
},
|
||||
"explore": {
|
||||
"heading": "Ознакомьтесь с нашими курсами",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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',
|
||||
|
||||
|
||||
Reference in New Issue
Block a user