Home
Support Forums

Netlify OAuth on Dev Environment retuns undefined

Hi!
I’m trying to use netlify-auth-providers to get a GitHub Token to use the GitHub API.

const authenticator = new netlify({
    site_id: "$mySiteId",
});

const authed = await authenticator.authenticate(
	{ provider: "github", scope: "user" },
	async (error, data) => {
		if (error) {
			return error;
		}
		return data;
	}
);

console.log({ authed }); // returns undefined

This works fine when deployed to Netlify, but I can’t get it to work for my local dev environment.
I’m using the netlify dev server to start my project:

$ netlify dev --live

When trying to authenticate, the netlify popup opens, and tells me that I’m authenticated, but the function always returns undefined. I’m expecting to get a GitHub token in data.

Is there something I’m missing? What do I need to do in order to authenticate (or mock an authentication) locally?

The app is deployed at apfelmark.netlify.app

Hi, @iamschulz and welcome to the community! :wave:

Could you please try running nuxt instead of netlify dev --live in your local dev environment and let us know if you still run into the issue?

Also, you could try rolling back to nuxt v2 from v3 to see if that helps.

Hi @audrey
You’re right - it seems to be an issue with nuxt3. I isolated the code and recreated the bit inside both nuxt 2 and nuxt 3 in identical environments. V2 works, v3 doesn’t.
When I log out the authenticator itself I get different results as well:

	const authenticator = new netlify({
		site_id: "$mysiteid",
	});
	console.log(authenticator);
        // nuxt 2: Authenticator {...}
        // nuxt 3: Authenticator2 {...}

I’ll open up a ticket at nuxt and link it here later.

1 Like