是的,您仍然可以使用AccountsJS。您可以直接从npm安装AccountsJS并使用它来添加身份验证功能。下面是一个示例,演示如何使用AccountsJS设置用户登录和注册:
安装AccountsJS:
npm install accounts-js
设置AccountsJS:
import { AccountsServer } from '@accounts/server';
import { AccountsPassword } from '@accounts/password';
// in memory database, do not use in production
const users = [];
const accountsPassword = new AccountsPassword({
  // see the options below
});
const accountsServer = new AccountsServer(
  {
    // We use the password service
    password: accountsPassword,
  },
  {
    // We use an in-memory database, so every time we run our server we clean any data
    // This options should be false in production
    db: {
      dropCollection: true,
    },
    // Instead of a real email server we mock it
    email: {
      from: 'test@test.com',
    },
  }
);
accountsServer.onNewUser(user => {
  users.push(user);
});
export default accountsServer;
使用AccountsJS:
import accountsServer from './accounts';
// Sign up a new user
const userId = await accountsServer.createUser({
  username: 'user123',
  password: 'password',
});
// Login using user credentials
const tokens = await accountsServer.loginWithPassword({
  user: {
    username: 'user123',
  },
  password: 'password',
});