TypeError: GoTrue is not a constructor

I’m trying the following:

const { GoTrue } = require('gotrue-js');

const auth = new GoTrue({
  APIUrl: "https://hm-pantry.netlify.app/.netlify/identity",
  audience: "",
  setCookie: false
});

I’ve tried looking through the issues of the repo but there doesn’t seem to be any solid documentation. Would appreciate any help. My aim is to be able to write some tests for my functions and that requires authentication.

I get the following error when trying this: TypeError: GoTrue is not a constructor

It looks like you are trying to destructure a GoTrue method from the gotrue-js package. Note that there is not GoTrue method. You’ll want to just import the package as GoTrue. Like so:

const GoTrue = require('gotrue-js')

With no curly braces. Let me know if that helps.

I got the same issue when trying it without Dennis. I thought I was doing something wrong.
I should add that this is running as part of a Jest test so not sure if that changes something. I am trying to test another Netlify function that I want to work with authentication but not sure how to get it to create a session in the test so that I can pull it out in the context of the Netlify function

Hey @bikingbadger,
Shooting in the dark here but have you tried import instead of require?

If you’d be willing to share a repo, that might help us as well.

I did actually start with the import like the docs but it didn’t work. So that is why I converted it to require. Wondering whether this has something to do with it being in a function.

I’d really appreciate an example repo if you have one. No better way of learning than seeing a working example