feat(#146): allow loading license from server config
Allow loading license from server config, so that:
- Don't need to hardcode the license to the source file
schema.json - Fix the license error in production because of using the hardcoded development key
- Allow different license keys in different environments
For verifying it, I've published a fork @jeff-tian/strapi-plugin-ckeditor, which works as expected.
Server Config
Add a CKEDITOR_LICENSE_KEY to the environment variable to allow the client side to load:
Sorry to ping you @Mgsy, @Reinmar but can we please get this in soon? (This is blocking our strapi 5 upgrade actually because having the key in each file is very cumbersome.)
Is there a permissions issue for /ckeditor/config? I'm still on Strapi 4, but receiving a 401 unauthorized error.
Per Claude (but works on my machine):
Fix CKEditor License Key Authentication Issue
Problem
The /ckeditor/config endpoint was returning 401 Unauthorized errors, causing the CKEditor to be stuck on "Loading License Key..." indefinitely.
Root Cause
The CKEditor plugin was using the deprecated request function from @strapi/helper-plugin, which wasn't properly handling authentication headers for admin API
calls.
Solution
Updated the license API to use the modern useFetchClient hook while maintaining clean abstraction:
Key Changes:
- Replaced deprecated
requestfunction withuseFetchClienthook - Maintained API abstraction by using dependency injection pattern
- Added proper error handling with console logging for debugging
- Updated React dependencies to follow hooks best practices
Files Modified
src/plugins/strapi-plugin-ckeditor/admin/src/api/license.js
- import { request } from "@strapi/helper-plugin";
-
- const licenseRequests = {
- getLicense: async () => await request(`/ckeditor/config`, { method: "GET" }),
- };
-
- export default licenseRequests;
+ const licenseRequests = {
+ getLicense: async (fetchClient) => {
+ const response = await fetchClient.get("/ckeditor/config");
+ return response;
+ },
+ };
+
+ export default licenseRequests;
src/plugins/strapi-plugin-ckeditor/admin/src/components/CKEditorProvider/index.js
import { memo, useEffect, useState } from "react";
import { useCKEditorCloud } from "@ckeditor/ckeditor5-react";
- import licenseRequests from "../../api/license";
+ import { useFetchClient } from "@strapi/helper-plugin";
+ import licenseRequests from "../../api/license";
const { options } = attribute;
+ const fetchClient = useFetchClient();
const [licenseKey, setLicenseKey] = useState(options?.licenseKey);
useEffect(() => {
- licenseRequests.getLicense().then((response) => {
+ licenseRequests.getLicense(fetchClient).then((response) => {
const licenseKeyFromServer = response.data?.ckeditor?.licenseKey;
if (licenseKeyFromServer) {
setLicenseKey(licenseKeyFromServer);
}
- });
- }, []);
+ }).catch((error) => {
+ console.error("Failed to fetch CKEditor license key:", error);
+ });
+ }, [fetchClient]);
Technical Details
The useFetchClient hook automatically:
* Adds JWT authentication headers via request interceptors
* Handles 401 responses with automatic logout
* Uses the supported Strapi v4 API patterns
Benefits
* ✅ Resolves authentication errors for CKEditor license endpoint
* ✅ Maintains clean code architecture with proper abstraction
* ✅ Uses modern, supported Strapi APIs instead of deprecated functions
* ✅ Improves error handling and debugging capabilities
* ✅ Follows React hooks best practices
Testing
* License key should now load successfully for authenticated admin users
* "Loading License Key..." message should disappear after successful API call
* CKEditor should initialize with proper license configuration
Is there a permissions issue for /ckeditor/config? I'm still on Strapi 4, but receiving a 401 unauthorized error.
This PR is for Strapi v5, and tested it worked very well.
using v5.23 i experience 401 as well on fetching keys