Updates to GoTrue.js Documentation

Hi. I’ve been working with the GoTrue API using the GoTrue.js library you all provide. The docs and particularly the interactive API docs are very good, but there are some difficulties I had with the documentation that I thought it would be useful to clarify.:

  • Documentation on how to add user metadata when creating a user
  • Documentation of the secondary cookie attribute for methods that manage log in
  • Documentation on how to update user metadata when updating a user
  • No method or documentation (that I could find) for handling the update token sent when a user updates their email

To be clear, I was able to figure all these things out (except for the last one) but not without a lot of digging through code. Some things, like the cookie parameter, do appear in the readme but not the interactive example docs. Others, like addng/updating user metadata, I couldn’t find documented.

Just trying to make it easier on the next person :wink: Let me know if I can help with this effort.

Hey @remotesynth and thanks for getting in touch :+1:

I’ll add @Perry in on this who may wish to bring this to the docs team when they next meet (or ask you a couple more questions!)

I’m also very up for helping with this and have spent quite a bit of time digging through the Go source to work things out as well :slight_smile:

@remotesynth are you still looking for how to handle the update token on email change?


@jonsully I never did implement the ability to change your email because I could not find documentation on how to do this, so that would be helpful.

Is this for CFE? :grin: :nerd_face:

I stepped away from the site I was going deep on Identity with for a while… let me see…

So based on what you wrote above it sounds like you’re fine with executing the update request, you’re just looking for how to handle the token in the URL in the email sent to the user to confirm their new email address. That URL will contain #email_change_token=ai-csfwfILRLUrVpA68a_w or the like.

The one key note about the email update token in particular is that the user has to have a JWT prior to clicking that link. E.g. they have to already be logged in. As long as that’s the case, and presuming that you’re using gotrue-js (per my assuming this is the CFE repo), you just have to run user.update() and specifically use the top level key email_change_token, so, with the above,

user.update({ email_change_token: 'ai-csfwfILRLUrVpA68a_w' })

That will confirm the new email and should re-hydrate a new JWT in the client localstorage / cookie

@remotesynth did that help? Just wanted to follow up! Been off the Community for a few weeks so just checking in :slight_smile:

1 Like