Accounts Service

Registration and Login

The most common register, login, and user_token-returning flow in @downcity/services.

AccountsService gives a downcity the shared account infrastructure, but email registration and login are available only when an email accounts provider is mounted and configured.

Before rendering an email form, ask the server which providers are enabled:

const providers = await guest.service("accounts").get("providers");

Render email registration or login only when the response contains an enabled email provider.

register

const session = await guest.service("accounts").action("register").invoke({
  email: "[email protected]",
  password: "password123",
  city_id: "city_demo",
});

login

const session = await guest.service("accounts").action("login").invoke({
  email: "[email protected]",
  password: "password123",
  city_id: "city_demo",
});

Why city_id is included here

Because after successful login or registration, the service will usually request a user_token for that downcity context from City.

So it needs to know:

  • which downcity is currently being entered
  • which downcity context the token should be issued for

What happens after login succeeds

Do not keep using the guest client forever. Switch into a normal user-context client:

const user = new City({
  role: "user",
  city_url,
  city_id: "city_demo",
  user_token: session.user_token,
});