| 1 |
|
defmodule WalletAuth.Events.UserAuthenticated do |
| 2 |
|
@moduledoc "Emitted when a user successfully completes login." |
| 3 |
|
@behaviour WalletEvents.DomainEvent |
| 4 |
|
|
| 5 |
|
@impl true |
| 6 |
1 |
def event_name, do: "UserAuthenticated.v1" |
| 7 |
|
|
| 8 |
|
@impl true |
| 9 |
1 |
def event_version, do: 1 |
| 10 |
|
|
| 11 |
|
@doc "Builds the domain event map." |
| 12 |
:-( |
def build(user_id, session_id, opts \\ []) do |
| 13 |
1 |
%{ |
| 14 |
|
event_id: WalletSharedKernel.Correlation.new_request_id(), |
| 15 |
|
event_name: event_name(), |
| 16 |
|
event_version: event_version(), |
| 17 |
|
aggregate_id: user_id, |
| 18 |
|
correlation_id: Keyword.get(opts, :correlation_id, WalletSharedKernel.Correlation.new_correlation_id()), |
| 19 |
|
occurred_at: DateTime.utc_now(), |
| 20 |
|
payload: %{ |
| 21 |
|
user_id: user_id, |
| 22 |
|
session_id: session_id, |
| 23 |
|
device_id: Keyword.get(opts, :device_id), |
| 24 |
|
ip_address: Keyword.get(opts, :ip_address) |
| 25 |
|
} |
| 26 |
|
} |
| 27 |
|
end |
| 28 |
|
end |