1
votes

I'm attempting to retrieve a user from within firebase functions using the admin API.

The code that is doing the work is:

async function getUserByUid(uid: string) {
    const user = await admin.auth().getUser(uid);
    return mapUser(user);
}

In my logs I can see 2 requests to get a user, one which works and another that does not.

Working

5:33:19.911 pm api Received request to get students for uid <Oge21mpIxaVQhVQblg61bhrZkZp1>

5:33:22.509 pm api Function execution took 2604 ms, finished with status code: 304

Not Working

11:47:08.849 pm api Received request to get students for uid <fhxxrstB02QhbXcYHDIKKsmQubV2>

11:47:10.983 pm api Error occurred { Error: There is no user record corresponding to the provided identifier. at FirebaseAuthError.FirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:42:28) at FirebaseAuthError.PrefixedFirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:88:28) at new FirebaseAuthError (/workspace/node_modules/firebase-admin/lib/utils/error.js:147:16) at /workspace/node_modules/firebase-admin/lib/auth/auth-api-request.js:518:15 at /workspace/node_modules/firebase-admin/lib/auth/auth-api-request.js:1476:13 at process._tickCallback (internal/process/next_tick.js:68:7) errorInfo: { code: 'auth/user-not-found', message: 'There is no user record corresponding to the provided identifier.' }, codePrefix: 'auth' }

In both cases, I can find the user in the authentication/users section of the firbase admin. The uid for both is definitely correct. Neither user is disabled.

My functions run in australia-southeast1 region. export const api = functions.region("australia-southeast1")

I'm at a loss trying to figure out why the same code that works for some users, does not work for others.

1

1 Answers

1
votes

Turns out that after I read the user in question I was then trying to retrieve data from one of their students that does not exist. Mystery solved.