k.account
Kooboo platform account: login status, current user, organization, and third-party login
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
Server-side KScript (k.api, <script env="server">, scheduled jobs) | Manages Kooboo platform console accounts only (distinct from k.commerce.membership) | Check auth state, sign platform users in/out, and navigate to user, organization, and oAuth APIs |
Quick Start
Check whether the current request carries a valid platform user session via k.account.isLogin, or sign in via k.account.login():
js
k.api.get(() => {
const u = k.account.user.current
return {
isLogin: k.account.isLogin,
userName: u ? u.userName : null
}
})
k.api.post(() => {
const user = k.account.login(k.request.form.username, k.request.form.password)
return {
isLogin: k.account.isLogin,
userName: user ? user.userName : null
}
})Quick Reference
| Method / Property | Description | Returns |
|---|---|---|
isLogin | Whether the current request has an authenticated platform user (details) | boolean |
login(username, password, code?) | Signs in with platform credentials and writes a JWT cookie (details) | User | null |
loginOrganization(username, password) | Signs in as an organization sub-account {username}@{orgId} (details) | User | null |
logout(returnUrl?) | Clears the login cookie and optionally redirects (details) | void |
ensureLogin(redirectUrl) | Redirects (302) to redirectUrl and ends the response if unauthenticated (details) | void |
user | Current user profile, username/email lookups, org switching, test tokens | k.account.user |
organization | Current/specified organization details, members, roles, departments, tenants | k.account.organization |
oAuth | Built-in and standalone OAuth login (WeChat, Google, Apple, AD, etc.) | k.account.oAuth |
Overview
k.account is used in site code to handle the login, identity, and organization information of Kooboo platform users (console accounts). It is different from the following APIs:
| API | Purpose |
|---|---|
k.account | Platform user login, k.account.user / organization, and third-party OAuth login |
k.payment | Site payment collection (orders, Alipay, Stripe, and other site payment integrations) |
k.commerce.membership | Storefront e-commerce membership (shop customers), separate from platform console accounts |
k.cookie / k.session | Cookies and temporary session data for the current HTTP request (not the platform account system) |
Submodules
| Member | Doc | Description |
|---|---|---|
| (root) | login.md | isLogin, login, logout, getAccessToken, token checks, etc. |
user | user.md | Current user, username/email lookup, and test user tokens |
organization | organization.md | Current organization, members, roles, departments, and tenants |
oAuth | oauth.md | WeChat, Google, Facebook, Apple, Weibo, AD, and built-in OAuth |
TypeScript Definitions
ts
interface KAccount {
isLogin: boolean;
login(username: string, password: string, code?: string): User;
loginOrganization(username: string, password: string): User;
logout(returnUrl?: string): void;
ensureLogin(redirectUrl: string): void;
generateToken(userName: string, expireIn: number): string;
getAccessToken(): string;
setIdentity(token: string): void;
thirdPartyLogin(thirdPartyName: string, userName: string): ThirdPartyLoginInfo;
renewInfo(): RenewInfo;
user: KUser;
organization: KOrganization;
oAuth: kOAuth;
}Related Docs
- k.account — Login and Identity
- k.account.user
- k.account.organization
- k.account.oAuth
- k.payment — site payment integrations
- k.cookie — request cookies