Currently, I used facebook to login. but it doesnt return any email by default. So what i did was to just create username-password authentication and linked to facebook.but when im trying to resend email verification, it says user not found. So my question is, Can I really resend email to linked account?
BTW was able to receive initial email verification on that email after creating. but resend doesnt work:
try {
const domain = await this.parameterService.get(Config.AUTH0_DOMAIN);
const clientSecret = await this.parameterService.get(
Config.AUTH0_CLIENT_SECRET
);
const clientId = await this.parameterService.get(Config.AUTH0_CLIENT_ID);
const audience = await this.getAudience();
const management = await this.getAuth0Management();
const { data: user } = await management.users.get({ id: authId });
const dbIdentity = user.identities?.find((i) => i.provider === 'auth0');
// Get Management API token with update:users scope
const tokenResponse = await fetch(\`https://${domain}/oauth/token\`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
client_id: clientId,
client_secret: clientSecret,
audience: audience,
grant_type: 'client_credentials',
scope: 'update:users',
}),
});
if (!tokenResponse.ok) {
throw new Error('Failed to get Auth0 management token');
}
const tokenData = await tokenResponse.json();
const accessToken = tokenData.access_token;
// Create email verification job
const jobResponse = await fetch(\`${audience}jobs/verification-email\`, {
method: 'POST',
headers: {
Authorization: \`Bearer ${accessToken}\`,
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
user_id: \`${dbIdentity.provider}|${dbIdentity.user_id}\`,
client_id: clientId,
}),
});
if (!jobResponse.ok) {
const errorData = await jobResponse.json();
throw new Error(
\`Auth0 API error: ${errorData.message || 'Unknown error'}\`
);
}
} catch (err) {
throw new BadRequestException(
\`Failed to resend email verification: ${(err as Error).message}\`
);
}
the dbIdentity has this sample output:
{
profileData: { email: ātest+601@example.comā, email_verified: false },
connection: āUsername-Password-Authenticationā,
user_id: ā68f738efde12526d11f1f441ā,
provider: āauth0ā,
isSocial: false
}