meteor-accounts
Use when wiring up authentication in a Meteor 3 app. Triggers on accounts-password, accounts-base, OAuth (Google, Facebook, GitHub, Apple, Twitter, Meetup, Weibo), accounts-2fa, accounts-passwordless, ServiceConfiguration.configurations.upsertAsync, Accounts.createUserAsync, Accounts.setPasswordAsync, Accounts.forgotPassword, Accounts.resetPassword, Accounts.verifyEmail, useHttpOnlyCookies, clientStorage, Meteor.loginWithPasswordAnd2faCode, email verification. Use this skill when the user asks about signups, signins, or asks about token storage vs HttpOnly cookies.
- License 许可
- MIT
- 最近更新
- 2026-11-12
- Stars
- ★ 11
- Forks
- 3
01 前言 Front Matter
- name
- meteor-accounts
- license
- MIT
- metadata
- { "area": "auth", "kind": "knowledge", "author": "meteor", "bundle": [ "fullstack" ], "meteor": ">=3.0", "tagline": "Wire up authentication in Meteor 3 (accounts-password, OAuth providers, 2FA, passwordless, email verification).", "docs_synced_at": "2026-10-07" }
- description
- Use when wiring up authentication in a Meteor 3 app. Triggers on accounts-password, accounts-base, OAuth (Google, Facebook, GitHub, Apple, Twitter, Meetup, Weibo), accounts-2fa, accounts-passwordless, ServiceConfiguration.configurations.upsertAsync, Accounts.createUserAsync, Accounts.setPasswordAsync, Accounts.forgotPassword, Accounts.resetPassword, Accounts.verifyEmail, useHttpOnlyCookies, clientStorage, Meteor.loginWithPasswordAnd2faCode, email verification. Use this skill when the user asks about signups, signins, or asks about token storage vs HttpOnly cookies.
02 资源文件 6
- 参考文档references/eval-cases.md17.4 KB
- 参考文档references/http-only-cookies.md6.4 KB
- 参考文档references/oauth-services.md6.2 KB
- 参考文档references/password-flows.md2.9 KB
- 参考文档references/passwordless-requests.md5.3 KB
- 参考文档references/users-collection.md2.4 KB
03 SKILL.md 正文
Meteor accounts
accounts-base plus a flavor package (accounts-password,
accounts-google, etc.). Meteor stores users in Meteor.users and ships
the client a resume token mapped to that document.
Decision flow
- Username + password? Add
accounts-password. - Social login? Add
accounts-baseplus the provider package (e.g.accounts-google) and configure the service. - Magic-link? Add
accounts-passwordless. - 2FA? Layer
accounts-2faon top ofaccounts-password. - Token storage on the client? Default is Web Storage. Meteor 3.3+ supports an HttpOnly cookie flow; see the section below.
For a custom users collection, configure both runtimes before app reads or validators. Meteor 3.6 fixes collection setup and publication lookup; review collection identity and client-write policy before changing profile rules.
Username + password
// server/accounts.js
import { Accounts } from "meteor/accounts-base";
import { Meteor } from "meteor/meteor";
Meteor.startup(() => {
Accounts.config({
sendVerificationEmail: true,
});
Accounts.emailTemplates.siteName = "My App";
Accounts.emailTemplates.from = "no-reply@example.com";
});
The from address is required; Meteor 3.5+ logs a server warning if you
omit it.
Do not set forbidClientAccountCreation: true when the client signup form
calls Accounts.createUser or Accounts.createUserAsync. The server rejects
that request with 403 Signups forbidden. For invite-only or administrator
provisioning, set the option on both client and server, remove the public
signup UI, and call Accounts.createUserAsync only from trusted server code
after its own authorization check.
// client/signin.js (Meteor 3.5+)
import { Meteor } from "meteor/meteor";
import { Accounts } from "meteor/accounts-base";
async function signUp({ email, password }) {
await Accounts.createUserAsync({ email, password });
}
async function signIn({ email, password }) {
await Meteor.loginWithPasswordAsync(email, password);
}
Client Accounts.createUser(options, callback) also remains supported.
Meteor.loginWithPasswordAsync was added in Meteor 3.5; on older 3.x use
the callback form of Meteor.loginWithPassword or wrap it in a Promise.
On the server use await Accounts.createUserAsync(options) and
await Accounts.setPasswordAsync(userId, newPassword).
HttpOnly cookies (Meteor 3.3+)
Default token storage is Web Storage. To move the resume token into an HttpOnly cookie and keep the client tab in-memory only:
// server
Meteor.startup(() => {
Accounts.config({
clientStorage: "none",
useHttpOnlyCookies: true,
});
});
// settings.json (public; surfaces the same flags to the client)
{
"public": {
"packages": {
"accounts": {
"clientStorage": "none",
"useHttpOnlyCookies": true
}
}
}
}
After restart and login, Meteor.loginToken* no longer appears in
localStorage; the browser receives an HttpOnly meteor_login_token
cookie. Each tab keeps its own in-memory credentials. DDP authentication still
reads the resume token into memory; this does not protect it from a malicious
script already executing in the application origin.
With accounts-base@3.3.1 (Meteor 3.5.2), the server handles cookie endpoints
only when it is opted in too. A client-only setting can therefore produce an
HTML response or 404 from later handlers. The /set body limit is 4096 bytes;
larger requests return HTTP 413. See
cookie endpoint troubleshooting for the
routes, version boundary, and diagnostic checks. Meteor 3.6's
accounts-base@3.4.0 also requires trusted origins and valid tokens,
uses SameSite=Strict, and adds a separate per-address endpoint rate limit.
Review custom callers and cross-site entry flows before upgrading. Distinguish invalid sessions from transient or
rate-limit responses before retrying or discarding credentials.
OAuth (Google example)
// server/oauth.js
import { ServiceConfiguration } from "meteor/service-configuration";
await ServiceConfiguration.configurations.upsertAsync(
{ service: "google" },
{
$set: {
clientId: process.env.GOOGLE_CLIENT_ID,
secret: process.env.GOOGLE_CLIENT_SECRET,
loginStyle: "popup",
},
},
);
// client
Meteor.loginWithGoogle(
{ requestPermissions: ["email", "profile"] },
(err) => { if (err) console.error(err); },
);
loginStyle: "redirect" for mobile or environments without
window.close / window.opener. Each provider ships its own
accounts-<service> package: accounts-google, accounts-github,
accounts-facebook, accounts-twitter, accounts-apple,
accounts-meetup, accounts-weibo.
For native Google/Facebook login, see native token validation.
To encrypt OAuth secrets at rest, add oauth-encryption and pass
oauthSecretKey to Accounts.config. This seals the provider application
secret in ServiceConfiguration.configurations.secret and the supported
provider-specific user token fields. It does not create a generic
Meteor.users.services.<provider>.secret field. See meteor-security.
Email verification and reset
// client
Accounts.forgotPassword({ email }, (err) => { ... });
// reset page
Accounts.resetPassword(token, newPassword, (err) => { ... });
// verify email
Accounts.verifyEmail(token, (err) => { ... });
Customize the URL pattern that lands in the email:
Accounts.urls.resetPassword = (token) =>
Meteor.absoluteUrl(`reset/${token}`);
Accounts.urls.verifyEmail = (token) =>
Meteor.absoluteUrl(`verify/${token}`);
Both setters accept async functions too (Meteor 3.x).
Customize the message:
Accounts.emailTemplates.resetPassword.subject = () => "Reset your password";
Accounts.emailTemplates.resetPassword.text = (user, url) =>
`Reset link: ${url}`;
Passwordless
Add accounts-passwordless. Request a one-time code or link, then submit the
code with the same selector:
Accounts.requestLoginTokenForUser(
{
selector: { email },
userData: { email },
options: { userCreationDisabled: false },
},
(error) => { if (error) console.error(error); },
);
Meteor.passwordlessLoginWithToken(
{ email },
token,
(error) => { if (error) console.error(error); },
);
Set userCreationDisabled: true for sign-in-only flows. Configure
tokenSequenceLength, loginTokenExpirationHours, and the
Accounts.emailTemplates.sendLoginToken template on the server. Treat the
token-request method as an abuse-sensitive endpoint and rate-limit repeated
requests. With Meteor 3.6's accounts-passwordless@3.1.2
and accounts-base@3.4.0, the complete request is validated before
lookup/creation and joins the default Accounts DDP rate rule. See
passwordless request boundaries
for custom callers, one-time completion, 2FA and earlier packages. Retain the
default limiter and handle callback errors without an immediate retry loop.
2FA
accounts-2fa adds TOTP. The login flow:
- Client calls
Meteor.loginWithPasswordAsync(user, password)on Meteor 3.5+, or the callback form ofMeteor.loginWithPasswordon older 3.x. - Server rejects with
error.error === 'no-2fa-code'. - Client prompts for a code, retries with
Meteor.loginWithPasswordAnd2faCode(user, password, code, cb).
Anti-patterns
- Store the OAuth secret in
Meteor.settings.public. The client seespublic. Put secrets at the top level ofsettings.json. - Build a custom password hash.
accounts-passworduses bcrypt; trust it. - Bypass
forbidClientAccountCreationwith a method that takes a password. Same risk. - Run
Accounts.config({ ... })inside a deferred path. Call it at top level or inMeteor.startup.
See also
references/password-flows.mdreferences/oauth-services.mdreferences/eval-cases.md- For OAuth-secret encryption and CSP, see the
meteor-securityskill.
04 同仓库更多 Skills
migrate-to-rspack
Use when migrating an existing Meteor app to Rspack (Meteor 3.4+), or upgrading Rspack 1 to 2 on Meteor 3.6. Triggers on nested imports, mainModule entry points, server-only apps, replacing fourseven:scss / meteor/less / coffeescript / jorgenvatle:vite / zodern:melte with loaders, Svelte/TypeScript preprocessing or Lingui SWC plugin failures after upgrade, CommonJS default-import interop, module.exports in client graphs, Node built-ins in browser code, _build / build-assets / build-chunks, .meteorignore hiding handoff files, dynamic chunks under ROOT_URL, meteor.modules for CSS/HTML, resolve.symlinks or resolve.alias migration, automatic dependency updates and immutable CI/Docker builds. Use this skill when the user asks about migration compatibility or a build plugin's Rspack replacement. For new-app setup and rspack.config.js helpers, use meteor-modern-build-stack instead.
migrate-to-meteor-3
Use when migrating a Meteor 2.x application to Meteor 3.x. Triggers on callAsync, *Async Mongo, removed Fibers, implicit-global ReferenceError, lost Blaze reactivity, a publish function returning a Promise, a scheduler dropping a Promise, a read API receiving update modifiers, async allow/deny, an Iron Router controller not running, "Method stub took too long", Atmosphere resolution, Express 5 WebApp handlers, lost async context, rawCollection callbacks, TypeScript declaration failures during upgrades, useTracker, and useSubscribe. Use this skill when the user asks about upgrading Meteor, async caller propagation, iterators with await, or replacing and forking packages. Standalone declarations and type-checking belong to meteor-typescript.
meteor-typescript
Use when setting up or repairing Meteor application declarations, TypeScript configuration, JavaScript IntelliSense, or local and CI type-checking. Triggers on meteor types, meteor/* imports resolving to any, missing declarations, duplicate Meteor identifiers, zodern:types, @types/meteor, .meteor/types, tsconfig.json, jsconfig.json, and tsc --noEmit in a Meteor app. Use this skill when choosing or migrating declaration providers without changing the app's runtime or bundler. For a Meteor 2-to-3 runtime migration use migrate-to-meteor-3 first; for SWC/Rspack compilation use meteor-modern-build-stack or migrate-to-rspack. General TypeScript language questions and Atmosphere declaration publishing are outside this app scope.
meteor-testing
Use when setting up, designing, writing, or repairing tests and test harnesses in a Meteor 3 app. Triggers on meteortesting:mocha, --driver-package, TEST_WATCH, TEST_BROWSER_DRIVER, MOCHA_GREP, meteor.testModule, focused tests, .only, Meteor.server.method_handlers, Meteor.server.publish_handlers, DDP.connect, --full-app integration mode, sinon, async test signatures, Playwright/Cypress E2E. Use this skill when the user asks about test runners, asks about testing publications, or asks about Jest vs Mocha in Meteor. For a failing, hanging, or flaky test whose failing layer or root cause is unknown, use meteor-debugging before changing the test or app.
meteor-security
Use when auditing or hardening a Meteor 3 application. Triggers on missing check() on method arguments, missing this.userId guards on publications, browser-policy CSP, DDPRateLimiter rules, oauth-encryption via Accounts.config oauthSecretKey, audit-argument-checks, allow/deny legacy patterns, BrowserPolicy.content.disallowInlineScripts, BrowserPolicy.framing.disallow. Use this skill when the user asks about hardening, asks about a security review, or asks about CSP for a third-party script (Stripe, Google Maps, fonts).
meteor-react
Use when building or debugging React interfaces in Meteor 3: meteor create --react, createRoot, JSX or TSX entry points, Rspack React detection, Fast Refresh, react-meteor-data, useTracker, useSubscribe, useFind, withTracker, Suspense, and Tracker.withComputation. Triggers on isLoading being treated as a boolean, useFind receiving fetch(), stale closure inputs, duplicate tracker side effects, unstable Suspense keys, lost reactivity after await, state reset after refresh, or React tests leaking computations. Use this skill when the user asks about a React skeleton, React Compiler, React-specific rspack.config rules, reactive data hooks, or classic versus Suspense integration. Route general bundler configuration to meteor-modern-build-stack and Meteor 2 upgrades to migrate-to-meteor-3.