// Web frontend project development rules. Use this skill when developing web frontend pages, deploying static hosting, and integrating CloudBase Web SDK.
| name | web-development |
| description | Web frontend project development rules. Use this skill when developing web frontend pages, deploying static hosting, and integrating CloudBase Web SDK. |
| alwaysApply | false |
Use this skill for Web frontend project development when you need to:
Do NOT use for:
Follow project structure conventions
src directorydist directorycloudfunctions directoryUse CloudBase Web SDK correctly
envQuery tool to get environment IDDeploy and preview properly
npm install is executed)publicPath configurationDirectory Organization:
src directorydist directorycloudfunctions directoryBuild System:
Routing:
Static Hosting Deployment:
Local Preview:
npx live-serverPublic Path Configuration:
publicPath and similar configurations should use relative paths instead of absolute paths@cloudbase/js-sdk@latest in the web applicationImportant: Authentication must use SDK built-in features. It is strictly forbidden to implement login authentication logic using cloud functions!
import cloudbase from "@cloudbase/js-sdk";
const app = cloudbase.init({
env: "xxxx-yyy", // Can query environment ID via envQuery tool
});
const auth = app.auth();
// Check current login state
let loginState = await auth.getLoginState();
if (loginState && loginState.user) {
// Logged in
const user = await auth.getCurrentUser();
console.log("Current user:", user);
} else {
// Not logged in - use SDK built-in authentication features
// Method 1: Redirect to default login page (recommended)
await auth.toDefaultLoginPage({});
// Method 2: Anonymous login
// await auth.signInAnonymously();
}
Initialization rules (Web, @cloudbase/js-sdk):
import("@cloudbase/js-sdk")initCloudBase() with internal initPromise cachesapp/auth instance in your frontend app; reuse it instead of re-initializingapp, auth, db, or other SDK objects, confirm it exists in the official CloudBase Web SDK documentationWhen using auth.toDefaultLoginPage() in local development, you must proxy the /__auth path to your CloudBase Web hosting domain. For example, in a Vite + React project:
// vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()],
base: "./", // Use relative paths to avoid asset issues on static hosting
server: {
host: "127.0.0.1",
proxy: {
"/__auth": {
target: "https://envId-appid.tcloudbaseapp.com/", // Replace with your CloudBase Web app domain
changeOrigin: true,
},
},
allowedHosts: true,
},
});
The CloudBase Web hosting domain can be obtained via the CloudBase MCP envQuery tool (Static hosting config); in the response, use the value from the StaticDomain field.
In other dev servers/build tools (Webpack dev server, Next.js custom dev server, etc.), implement an equivalent proxy rule so that all /__auth requests are forwarded to the CloudBase domain during local development.
Must use SDK built-in authentication: CloudBase Web SDK provides complete authentication features, including default login page, anonymous login, custom login, etc.
Forbidden to implement login using cloud functions: Do not create cloud functions to handle login logic, this is the wrong approach
User data management: After login, user information can be obtained via auth.getCurrentUser(), then stored to database
Error handling: All authentication operations should include complete error handling logic
Web project build process: Ensure npm install command has been executed first, then refer to project documentation for building