# Actions after create the user? (Registration+creation)

**URL:** <https://forum.keycloak.org/t/actions-after-create-the-user-registration-creation/19193>\
**Category:** Tips and tricks\
**Created:** [December 19, 2022, 2:33am UTC](https://forum.keycloak.org/t/actions-after-create-the-user-registration-creation/19193 "2022-12-19T02:33:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hermesalvesbr](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/hermesalvesbr/32/7270_2.png) [@hermesalvesbr](https://forum.keycloak.org/u/hermesalvesbr)\
**Post date:** [December 19, 2022, 2:33am UTC](https://forum.keycloak.org/t/actions-after-create-the-user-registration-creation/19193/1 "2022-12-19T02:33:13Z")

</div>

Hi there,

I’m a new user of keycloak, few days and studying…

Some material teaching actions hooks after user create? I need to create a database for some user created in my keycloak. It’s for a multi tenant saas app.

What’s the best way for delivery multi databases or multi schemas with keycloak after user registration?

---

<div class="post-metadata">

**Author:** ![jblachly](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jblachly/32/6657_2.png) [@jblachly](https://forum.keycloak.org/u/jblachly)\
**Post date:** [January 14, 2023, 9:25pm UTC](https://forum.keycloak.org/t/actions-after-create-the-user-registration-creation/19193/2 "2023-01-14T21:25:38Z")

</div>

I had the same question and did a lot of searching. Ultimately, unless you can write your own SPI (service provider interface) in Java, you are out of luck. If you can, you write an SPI event listener that listens for new user registration, then triggers an external action (create user in app database, etc.).

Our solution instead was to disable registration through Keycloak, and have a separate registration app, which created user in Keycloak and the backend API database; or not at all. Likewise we created an admin CLI that could do the same thing.

---

<div class="post-metadata">

**Author:** ![xgp](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/xgp/32/2589_2.png) [@xgp](https://forum.keycloak.org/u/xgp)\
**Post date:** [January 15, 2023, 8:51am UTC](https://forum.keycloak.org/t/actions-after-create-the-user-registration-creation/19193/3 "2023-01-15T08:51:07Z")

</div>

I have some base classes for listening to user create events if you’re willing to implement your own event listener:

> **[GitHub - p2-inc/keycloak-events: Useful Keycloak event listener...](https://github.com/p2-inc/keycloak-events#user-change-listener)**
>
> Useful Keycloak event listener implementations and utilities. - GitHub - p2-inc/keycloak-events: Useful Keycloak event listener implementations and utilities.

The example there should be easy to follow:

```java
public class MyUserAddRemove extends UserEventListenerProviderFactory {

  @Override
  public String getId() {
    return "ext-event-myuseraddremove";
  }

  @Override
  UserChangedHandler getUserChangedHandler() {
    return new UserChangedHandler() {
      @Override
      void onUserAdded(KeycloakSession session, RealmModel realm, UserModel user) {
        log.infof("User %s added to Realm %s", user.getUsername(), realm.getName());
      }

      @Override
      void onUserRemoved(KeycloakSession session, RealmModel realm, UserModel user) {
        log.infof("User %s removed from Realm %s", user.getUsername(), realm.getName());
	  }
    };
  }

}

```
