I’m using Auth0 for authentication. I’m trying to find currentUser.email field. I want to save this email for potential future migration. It looks like the object does not have the email field. Here’s an example data for currentUser:
{
iss: 'https://dev-4-ozihdc.auth0.com/',
sub: 'auth0|5ee53543e4647b00137025dd',
aud: [
'https://dev-4-ozihdc.auth0.com/api/v2/',
'https://dev-4-ozihdc.auth0.com/userinfo'
],
iat: 1592079735,
exp: 1592166135,
azp: 'RFI3tsaUePpAMtVv9u3Td07eejT6BTiL',
scope: 'openid profile email'
}
I see the email field in currentUser on the client-side, but not the server-side. How do I retrieve it on the server-side?
peterp
June 14, 2020, 6:36am
#2
You can add it to the jwt by using Auth0’s rules as described over here: https://community.auth0.com/t/email-address-missing-in-access-token-when-using-google-cloud-endpoint/11444/5
We should probably add this to the Redwood’s Auth docs!
2 Likes
@peterp thanks very much. I figured it out now. It is confusing as the rule needs to be added inside Auth0 Auth Pipeline. I was trying to add it into getCurrentUser function.
2 Likes
Potentially related with a different take on the setup (just fyi):
Here’s how I implemented getCurrentUser with Auth0. I used Auth0’s sub as the User id, but I wouldn’t recommend that.
// api/src/lib/auth.js
import { AuthenticationError } from '@redwoodjs/api'
import { AuthenticationClient } from 'auth0'
import { db } from './db'
const auth0 = new AuthenticationClient({
domain: process.env.AUTH0_DOMAIN,
clientId: process.env.AUTH0_CLIENT_ID,
})
export const getCurrentUser = async (jwt, accessToken) => {
// try to find the user
let user = await db.us…
1 Like