# How to check its first time user created account in nakama?

**URL:** <https://forum.heroiclabs.com/t/how-to-check-its-first-time-user-created-account-in-nakama/5885>\
**Category:** Runtime Framework\
**Created:** [December 21, 2024, 7:39pm UTC](https://forum.heroiclabs.com/t/how-to-check-its-first-time-user-created-account-in-nakama/5885 "2024-12-21T19:39:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![virtouso](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/virtouso/32/679_2.png) [@virtouso](https://forum.heroiclabs.com/u/virtouso)\
**Post date:** [December 21, 2024, 7:39pm UTC](https://forum.heroiclabs.com/t/how-to-check-its-first-time-user-created-account-in-nakama/5885/1 "2024-12-21T19:39:35Z")

</div>

i need to know if its first time user logged in.

if its first time initialize database for it otherwise make session from database. based on docs I have done like this:

```auto
func InitializeEmailLogin(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateEmailRequest) (*api.AuthenticateEmailRequest, error) {
	// Only run this logic if the account that has authenticated is new.
	userId, ok := ctx.Value(runtime.RUNTIME_CTX_USER_ID).(string)}

```

if ‘ok’ is false it means use has registered before. the problem is ok is always false.

---

<div class="post-metadata">

**Author:** ![virtouso](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/virtouso/32/679_2.png) [@virtouso](https://forum.heroiclabs.com/u/virtouso)\
**Post date:** [December 21, 2024, 11:34pm UTC](https://forum.heroiclabs.com/t/how-to-check-its-first-time-user-created-account-in-nakama/5885/2 "2024-12-21T23:34:39Z")

</div>

i think i got my answer.

in before login hook, no user id is initialized but can modify session variables. in after login hook can not add session variables while session is already created. have access to userName and userId but session is immutable.

i wanted to read user leaderboard tier and write it on the session to ignore reading tier from database anytime sending new score but it seems impossible

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [December 23, 2024, 12:13pm UTC](https://forum.heroiclabs.com/t/how-to-check-its-first-time-user-created-account-in-nakama/5885/3 "2024-12-23T12:13:10Z")

</div>

The `authenticate` response has a `created` param that says whether the account is newly created or not, you can access this in an after-hook.

If you’re using TS or Lua then yes, the object cannot be currently mutated in the after-hook, but it works in Go.

If you can’t store the tier in the session-variables just create an RPC or make this data part of a storage object that you read from the client once, then cache it in the client and update it as needed.

Best.

---

<div class="post-metadata">

**Author:** ![virtouso](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/virtouso/32/679_2.png) [@virtouso](https://forum.heroiclabs.com/u/virtouso)\
**Post date:** [December 23, 2024, 12:53pm UTC](https://forum.heroiclabs.com/t/how-to-check-its-first-time-user-created-account-in-nakama/5885/4 "2024-12-23T12:53:14Z")

</div>

it’s tested. im using go backend. when I mutate the session in after authenticating hook and want to access it from other API, it returns empty.
