Rejecting Authentication in AfterHook

Hi,

I am using the CustomAuthentication to authenticate with another service.
I want to store some information on Nakama about a custom account ID and then each login query that to make sure the AccountID from the client matches their original when they first logged in and an account was created.

If the AccountID they sent from the client doesn’t match that which we have on the backend I want to reject the auth, however, by the time the UserID is available to check the storage we’re in the afterHook and Auth has been granted.

I thought I could force a logout but then the client just re-auths next time it needs to make a request.

From my understanding there is no way to get the UserID during the beforeHook as it’s before the auth has occured.

Any help is greatly appreciated,
Thanks,

Rob.

@Wobling the after hook is executed after the authentication happened at which point it cannot be stopped.

You could contact the authentication provider in the beforeHook and guard the Nakama authentication from continuing if the values don’t match. However this means that each successful auth will go to the provider twice.

I want to store some information on Nakama about a custom account ID and then each login query that to make sure the AccountID from the client matches their original when they first logged in and an account was created.

If the AccountID they sent from the client doesn’t match that which we have on the backend I want to reject the auth

May I ask what’s the use-case for this?