Hi everyone,
I’m using Auth0-lock to create an authentication dialog.I want to create an auth-lock object in a NodeJS file.When I used :
const {Auth0Lock} = require('auth0-lock');
var lock = new Auth0Lock( MyClientId, MyDomain);
lock.show();
in my NodeJS file, I got the following error:
C:\Users.…\node_modules\auth0-lock\lib\utils\url_utils.js:6
var parser = global.document.createElement(‘a’);
^
TypeError: Cannot read property ‘createElement’ of undefined
I defined a virtual dom element for it, using jsdom as follow:
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const dom = new JSDOM('<!DOCTYPE html><html><body.....</body></html>');
global.window = dom.window;
global.document = dom.window.document;
global.location = dom.window.document.location;
By this, the above error was fixed, but I got another error without showing me the auth0-lock authentication dialog.It is:
Error: An error occurred when fetching client data for Lock: https://cdn.auth0.com/client/[MyClientId].js
Searches showed me this error indicates that Lock could not connect to the Auth0 CDN to fetch client. But when I uses auth0 cdn link and create auth-lock dialog in a html file using script as follow:
<script src="https://cdn.auth0.com/js/lock/10.23.1/lock.min.js"></script>
<script>
var lock = new Auth0Lock( MyClientId, MyDomain);
lock.show();
</script>
it worked with the exact same “MyClientId” and showed me the dialog.
Would you please help me to fix this problem and display the dialog in my NodeJS file?
Thanks