Meteor核心的特征
Before we get into all of the different user-facing accounts functionality you can add with Meteor, let's go over some of the features built into the Meteor DDP protocol and accounts-base
package. These are the parts of Meteor that you'll definitely need to be aware of if you have any user accounts in your app; most of everything else is optional and added/removed via packages.
DDP中的userId
DDP is Meteor's built-in pub/sub and RPC protocol. You can read about how to use it in the Data Loading and Methods articles. In addition to the concepts of data loading and method calls, DDP has one more feature built in - the idea of a userId
field on a connection. This is the place where login state is tracked, regardless of which accounts UI package or login service you are using.
This built-in feature means that you always get this.userId
inside Methods and Publications, and can access the user ID on the client. This is a great starting point for building your own custom accounts system, but most developers won't need to worry about the mechanics, since you'll mostly be interacting with the accounts-base
package instead.
`accounts-base`包
This package is the core of Meteor's developer-facing user accounts functionality. This includes:
- A users collection with a standard schema, accessed through
Meteor.users
, and the client-side singletonsMeteor.userId()
andMeteor.user()
, which represent the login state on the client. - A variety of helpful other generic methods to keep track of login state, log out, validate users, etc. Visit the Accounts section of the docs to find a complete list.
- An API for registering new login handlers, which is used by all of the other accounts packages to integrate with the accounts system. There isn't any official documentation for this API, but you can read more about it on the MeteorHacks blog.
Usually, you don't need to include accounts-base
yourself since it's added for you if you use accounts-password
or similar, but it's good to be aware of what is what.