@daisha
To get the user's email from Auth0 in your Node.js server, you need to follow these steps:
1
|
npm install auth0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
const ManagementClient = require('auth0').ManagementClient; const auth0 = new ManagementClient({ domain: 'YOUR_AUTH0_DOMAIN', clientId: 'YOUR_AUTH0_API_CLIENT_ID', clientSecret: 'YOUR_AUTH0_API_CLIENT_SECRET', }); const getUser = async (userId) => { try { const user = await auth0.getUser({ id: userId }); console.log('User email:', user.email); return user.email; } catch (error) { console.error(error); } }; getUser('USER_ID'); |
Replace 'YOUR_AUTH0_DOMAIN'
, 'YOUR_AUTH0_API_CLIENT_ID'
, 'YOUR_AUTH0_API_CLIENT_SECRET'
, and 'USER_ID'
with your own Auth0 domain, API client ID, client secret, and the ID of the user whose email you want to fetch.
By following these steps, you will be able to fetch the user's email from Auth0 in your Node.js server.