clientContext empty when invoking identity-login

Is clientContext for the current user included when the identity-login function is being called on a production site?

When testing using netlify functions:invoke it is empty.

Answering myself here. When running in production, the user object passed in the event payload contains an id reference which is sufficient for my needs.

1 Like

thanks for sharing that!

1 Like

I just hit a similar/same issue.

Following the Docs here implies that I should be able to find a user object on the context.clientContext when a logged-in user accesses a Netlify Function.

However this:

exports.handler = async function (event, context) {
  const { identity, user } = context.clientContext;
  return {
    statusCode: 200,
    body: JSON.stringify({ message: `Hello ${ user }` })
  };
}

… returns

{ message: Hello undefined }

I have confirmed that the user is logged in and as @kristoferlund says there is user data available in the event payload.

Am I missing something about the way this works?

Hi @james-king, When you invoke your function to you include an Authorization header with the value of 'Bearer '? The user object will only be available if that header is present.

Thanks @Dennis - I went another route and tried Okta instead which is working for me.

It turns out I cannot use Netlify Identity for my use case for the reasons outlined here. Would be great to have your input on that topic!