# Core Functions and Hooks

**URL:** https://heroiclabs.com/docs/hiro/server-framework/introduction/core-functions-and-hooks/
**Keywords:** core functions and hooks, hiro
**Categories:** hiro, core-functions-and-hooks, introduction

---


# Core Functions and Hooks

The Hiro interface defines core functions and hooks that aren't part of any specific system. You can use these hooks to insert your custom code, which will often need reference to certain Hiro systems that you can access by using the various methods listed below.

System specific functions and hooks live on their own pages, such as: [Achievements](../../achievements/) or [Economy](../../economy/).

## How To Access Hiro Systems

The following code snipped is an example from our [Level-Based Stats Guide](../../../guides/personalizer/level-based-stats/) where we take `systems` after initializing it, and pass it into our [Personalizer](../../../concepts/personalizer/). You can pass `systems` into any code that you have which needs access to Hiro systems.

```go
// ...
systems, err := hiro.Init(ctx, logger, nk, initializer, binPath, hiroLicense,
	hiro.WithBaseSystem(fmt.Sprintf("base-system-%s.json", env), true),
	hiro.WithEnergySystem(fmt.Sprintf("base-energies-%s.json", env), true),
	hiro.WithStatsSystem(fmt.Sprintf("base-stats-%s.json", env), true))
if err != nil {
	return err
}

staminaPersonalizer, err := NewStaminaPersonalizer(nk, systems.GetStatsSystem(), "stamina-personalizer.json")
if err != nil {
	return err
}
// ...
```

## Functions

### AddPersonalizer

Add a [Personalizer](../../../concepts/personalizer/) to the chain that is resolved when getting Hiro config data.

```go
systems.AddPersonalizer(hiro.NewStoragePersonalizerDefault(logger, initializer, true))
```

### AddPublisher

Add a Publisher that wishes to receive and process analytics-style events generated server-side by the various available Hiro systems.

```go
systems.AddPublisher(MyCustomPublisher)
```

### GetAchievementsSystem

Get reference to the [Achievements System](../../achievements/) if found in the registered systems.

```go
systems.GetAchievementsSystem()
```

### GetAuctionsSystem

Get reference to the [Auctions System](../../auctions/) if found in the registered systems.

```go
systems.GetAuctionsSystem()
```

### GetBaseSystem

Get reference to the [Base System](../../base/) if found in the registered systems.

```go
systems.GetBaseSystem()
```

### GetEconomySystem

Get reference to the [Economy System](../../economy/) if found in the registered systems.

```go
systems.GetEconomySystem()
```

### GetEnergySystem

Get reference to the [Energy System](../../energy/) if found in the registered systems.

```go
systems.GetEnergySystem()
```

### GetEventLeaderboardsSystem

Get reference to the [Event Leaderboards System](../../event-leaderboards/) if found in the registered systems.

```go
systems.GetEventLeaderboardsSystem()
```

### GetIncentivesSystem

Get reference to the [Incentives System](../../incentives/) if found in the registered systems.

```go
systems.GetIncentivesSystem()
```

### GetInventorySystem

Get reference to the [Inventory System](../../inventory/) if found in the registered systems.

```go
systems.GetInventorySystem()
```

### GetLeaderboardsSystem

Get reference to the [Leaderboards System](../../leaderboards/) if found in the registered systems.

```go
systems.GetLeaderboardsSystem()
```

### GetProgressionSystem

Get reference to the [Progression System](../../progression/) if found in the registered systems.

```go
systems.GetProgressionSystem()
```

### GetStatsSystem

Get reference to the [Stats System](../../stats/) if found in the registered systems.

```go
systems.GetStatsSystem()
```

### GetStreaksSystem

Get reference to the [Streaks System](../../streaks/) if found in the registered systems.

```go
systems.GetStreaksSystem()
```

### GetTeamsSystem

Get reference to the [Teams System](../../teams/) if found in the registered systems.

```go
systems.GetTeamsSystem()
```

### GetTutorialsSystem

Get reference to the [Tutorials System](../../tutorials/) if found in the registered systems.

```go
systems.GetTutorialsSystem()
```

### GetUnlockablesSystem

Get reference to the [Unlockables System](../../unlockables/) if found in the registered systems.

```go
systems.GetUnlockablesSystem()
```

## Hooks

### SetAfterAuthenticate

Set a custom function which will run after a user authenticates.

```go
systems.SetAfterAuthenticate(AfterAuthenticateFn)

func AfterAuthenticateFn(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, session *api.Session) error {
  // Trigger additional processes upon a user creating their account or logging in.
  return nil
}
```
