Set current_user.externalIdentifier during custom API authentication

I have an app that uses our REST API with custom authentication. Some of our endpoints require the current user's ID. I'm attempting to solve this by including a javascript step in the API custom authentication to set the current_user.externalId value. It appears that current_user is not defined in this context.

1 Like

Hi @rob_future,

Create User Attribute variables by going to the settings page and selecting the User Attributes option.

Once you’ve added the User Attribute variables, you can assign each variable different values for individual users.

Access the created variables as metaobjects in the app using {{ current_user.metadata.NAME }}. Here is doc

1 Like

Hey @rob_future! Thanks for reaching out.

The first thing I want to highlight is that current_user definitely is defined and accessible in the context of a custom auth flow, but the linter doesn't do a good job communicating that. The primary reason for this inconsistency is the fact that the code itself executes server-side, so the browser doesn't reliably know what is and is not in scope. It's something we're looking to improve!

Secondly, @ZeroCodez is absolutely right about how to define and initially set custom user attributes. Unfortunately, they can only be set via the UI or API. In your particular use case, it sounds like an admin will need to set an externalIdentifier for all users that can then be read within your custom auth flow.

I hope that helps! Let me know if you have any additional questions. :+1: