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:
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.
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
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.
1 Like
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.