Questions Related to Before/After Authentification Hook functions

Hello Guys,

im trying to create a referral system for my game, im using before and after hook functions,
i have few questions about them.

  1. how can i access the custom value sent from clients in the Authentification process from the before hook Go function ?
  2. is the Authentification before hook function is triggered only for successful Authentifications? (is there any risk of failure ?)
  3. is it possibile to know if the user is in a signin or signup process from the before hook ?
  4. is it possibile to access the custom authentification value passed in the after hook too?
  5. also what is the metadata passed in nk.WalletUpdate(ctx, userID, changeset, metadata, true) function ? is it the user metadata or a metadata related to the wallet transaction ?
    Thank you!

Hi @Opeth001,
You can check out this A way to know if a user is doing a sign in or sign up from google login post . I think it’ll answer most of your queries -

Also I’ll try to answer your queries here from my understanding of nakama,
1 - You can send the custom values with authentication request and access them inside the payload received in before hook. I think it’s not available yet on client side. Check out that post for more info and someone on the nakama team can clarify that for you.
2. Authentication before hook is triggered before authentication process even starts. Before hook for any type of request always executes first. If you don’t return the payload from before hook, request is not performed and returns back to client with error.
3. No, you can’t know that in before hook as authentication is not done in before hook unless you make a custom SQL call to db to know that which is not very efficient. But yes, you can know that inside the after hook, check for session object’s Created field for that.
4. Yes, you can access the initial request payload passed inside the after hook. Check here
5. As far as I understood, that metadata is related to wallet transaction. You can store custom info regarding a particular wallet transaction inside that metadata field.

I hope this helps.


Thank @hdjay0129 for your answers!

  1. it’s clear now thanks!
  2. i didnt get this one, does it mean the before authentification hook is triggered even if the authentification is about to fail ?
  3. clear!
  4. clear!
  5. clear!

@Opeth001 Glad to know it helped.
And yes, If there’s a before hook for Authentication, it’ll always be called. As you can imagine, request has not yet started to process actually inside before hook, so there’s no way to know if the authentication is going to fail or not at this point.
before_hook for request ->> actual request processing by nakama --> after hook for request

1 Like

Thank again @hdjay0129

1 Like