Email Address Verification

Hi,

I am new to game design/development. Just practicing with Godot and Nakama.
I’ve already implemented Registration & Login to Nakama server for testing purpose.
It works fine. I also followed a tutorial to use some features of Nakama to start a match between 2 players.
But I could not find any way to verify a user’s email before/after registering an account.

I see the following warning under a user account on the server:

Verification Status: Not Verified

But I could not find an API call to make it verified.

Also, I would like to learn best practice to verify a user’s email address.
Is this something should be done on Godot code ? is there a Nakama feature that could verify user’s email ?
Or should I implement a plugin ? On Godot or Nakama ?

thanks.

Hello @ilkeraktuna,

Have a look at this thread: How to verify user account? - #2 by sesposito.

Hope it helps.

1 Like

thank you. that’s a good start.
But I don’t understand how the hooks work. Can you provide some examples please ?

For example, you suggest to write an after hook which will work after the account creation event.
But I could not find an event for this in the list :

is that “AuthenticateEmail” ?
if so, will it be something like :

initializer.registerAuthenticateEmail(authenticateEmail);

let authenticateEmail: nkruntime.AfterHookFunction<void, nkruntime.registerAuthenticateEmailRequest> = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, data: void, request: nkruntime.registerAuthenticateEmailRequest) {
 // CODE to VERIFY
};

and what shall I do in that function ?

Yes you’d use an AuthenticateEmail after hook. You’d set it up like this:

function InitModule(ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, initializer: nkruntime.Initializer) {
    initializer.registerAfterAuthenticateEmail(sendVerificationEmailFn);
}

let sendVerificationEmailFn: nkruntime.AfterHookFunction<nkruntime.Session, nkruntime.AuthenticateEmailRequest> = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, data: nkruntime.Session, request: nkruntime.AuthenticateEmailRequest) {
    if (data.created) {
        // If this is true, the account was created for the first time.
        // User Third party service to send verification email here.
    }
};

thank you.
Unfortunately I know “zero” about hooks and Lua in general.

Is this the start of the script or should I pur something before that InitModule function ?
And what is “data.created” ?
How should I use it when sending email ?

I found an example Lua script which sends email here:

and another one for Gmail :

would this work if I use in the Nakama hook ?

The snippets I provided are in TypeScript not in Lua. The Lua runtime doesn’t have an entrypoint function, while you can mix and match to a degree with the different runtimes, I’d suggest you stick to a single language for simplicity.

If you’d prefer Lua instead of JS have a look at the examples here: nakama/data/modules at master · heroiclabs/nakama · GitHub.
You should be able to include external Lua modules and use the ones in the link you provided.

Hooks are just functionality that Nakama provides to have custom code be executed before and/or after its API calls. In this case we’re setting up an after hook for when the AuthenticateEmail API is used. In the hook, the returned value of the API is passed as the data param, and if data.created is true, it means that the account is new. Subsequent API calls to it with the same authentication params will not create a new user, and will return data.created as false, so we only send the verification email in the former situation, as you’d otherwise send it every time the user authenticates.

ok in this case which parameter provides the user’s email ?
I have to send a verification code to that email address.

The email can be fetched from request.account.email.

I think it would help if you’d have a look at Nakama: TypeScript Runtime | Heroic Labs Documentation and set up your development environment to take advantage of TypeScript types.

When I was working on a project, I faced a similar issue with email verification. After setting up user accounts, I realized I needed a way to verify emails before letting users fully register. I ended up using a bulk email verifier to clean up my email list first, which really helped me reduce the number of invalid addresses.

For email verification in Nakama, there’s typically no built-in API call for that, so I implemented a simple solution myself. I sent a verification link to the user’s email upon registration. Once they clicked it, I updated their status to verified in the database. It wasn’t too complicated, and it made the signup process feel more secure!