I need to extract information from a firebase auth credentials object that is formatted differently depending on the sign-in method being used.
For instance, for password sign up, the data I need is directly in credentials, but for Facebook or Google login, the data I need is in credentials.user.
So, I have this function set up:
parseCredentials(credentials: any): User {
const parsedCredentials: User = {
displayName: credentials.displayName || credentials.user.displayName,
email: credentials.email || credentials.user.email,
emailVerified: credentials.emailVerified || credentials.user.emailVerified,
uid: credentials.uid || credentials.user.uid
};
return parsedCredentials;
}
As you can see, I am using this function to create a new User object based on the provided credentials because unnecessary information should not be included in the User object.
The issue arises when signing up with an email-password combination and receiving the error: credentials.user is undefined.
I believe there may be an issue with the || operators. It appears that credentials.user is indeed undefined (due to the user property's absence on the credentials object during email-password sign up).
However, I employed the || operator precisely for this reason. I've been struggling with this problem for some time now and cannot seem to find a solution. Any assistance would be greatly appreciated. Thank you.